Change custom spinner selector

0

I created a custom spinner and custom dropdown spinner , when using them, the selector will be almost invisible and its color will not help either. I wanted my spinner selector to be larger, it could be the default size and I wanted another color, so I would go to the bottom of the layout. is in bold is my problem)

I tried to pass a color reference to the attribute in xml android:dropDownSelector and it still did not work. I'm going to put images here of two spinners.

Thisimagereferstoastandardspinner.Createdwiththislayout:android.R.layout.simple_spinner_itemandthenthedropdownlayoutconfiguredthisway:android.R.layout.simple_spinner_dropdown_itemnoadapter.Intheimageabovethespinnerwasnottouchedbytheuser,theimagebelowreferstothesamespinneronlywiththedifferencethatitisbeingtouchedbytheuser.

Now if by chance I use a custom spinner and a custom dropdown for the adapter, the selector gets almost invisible as I said. Let's now see pictures of how my custom spinner got.

Thesamecustomspinnerbelowjustnowselected.

Below is the code for my custom spinner and custom spinner dropdown.

custom_spinner_item.xml     

<TextView
    android:id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:gravity="center_vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="#fff"/>

<TextView
    android:id="@+id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:gravity="center_vertical"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="#fff"/>

</LinearLayout>

custom_spinner_dropdown_item.xml

<LinearLayout
android:id="@+id/linearLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#232323"
android:orientation="horizontal">

<TextView
    android:id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="#fff"/>

<TextView
    android:id="@+id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="#fff"/>

</LinearLayout>

Again remembering. I want the selector of my custom spinner to be larger and have a different color to go out to the bottom. The selector size could be the size of the default selector. I would also like to know why when I used a custom spinner the selector size was almost invisible and not the original size.

layout of the fragment:

<LinearLayout
android:id="@+id/layoutMain"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0F2028"
android:orientation="vertical"
android:padding="5dp">

<Switch
    android:id="@+id/switchButtonConcluidoIM"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:text="@string/concluido"
    android:textColor="#ffffffff"
    android:textOff="@string/nao"
    android:textOn="@string/sim"/>

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TableRow
                android:id="@+id/tableRow"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/textViewPrimario"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="@string/primario"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#55b76b"
                    android:textStyle="bold"
                    />

                <Spinner
                    android:id="@+id/spinnerPrimario"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp">

                <TextView
                    android:id="@+id/textViewSecundario"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="@string/secundario"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#55b76b"
                    android:textStyle="bold"/>

                <Spinner
                    android:id="@+id/spinnerSecundario"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

                <TextView
                    android:id="@+id/textViewLeitura"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="@string/leitura"
                    android:textColor="#ffffff"/>

                <EditText
                    android:id="@+id/editTextLeitura"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="5dp"
                    android:layout_weight="2"
                    android:background="@drawable/fields_border"
                    android:ems="10"
                    android:inputType="numberDecimal"/>

            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

                <TextView
                    android:id="@+id/textViewPolaridade"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="@string/polaridade"
                    android:textColor="#ffffff"
                    />

                <EditText
                    android:id="@+id/editTextPolaridade"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="5dp"
                    android:layout_weight="2"
                    android:background="@drawable/fields_border"
                    android:ems="10"
                    android:inputType="numberSigned"/>

            </TableRow>

            <TableRow
                android:id="@+id/tableRow5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

                <TextView
                    android:id="@+id/textViewObs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="@string/observacao"
                    android:textColor="#ffffff"
                    />

                <EditText
                    android:id="@+id/editTextObs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_weight="2"
                    android:background="@drawable/fields_border"
                    android:ems="10"/>
            </TableRow>

        </TableLayout>

    </TableLayout>
</ScrollView>

    
asked by anonymous 03.06.2014 / 19:57

1 answer

0

As I said on my leash, my problem was:

  

I wanted my spinner selector to be larger, it could be   standard size and wanted another color, so if you get out to the bottom of the   layout.

Let's go to the first case, the selector that was almost invisible is larger. The problem with it is that because it was in a% w of% the selector was that size. I ran a test with TableRow out of Spinner and the selector was large, the default size. To solve this problem without having to change the TableRow that contained TableRow , I inserted the Spinner attribute and set its width to android:layout_weight="1" .

On the second case, the selector was dark, it needed to be clearer. I had to apply wrap_content to my style . The code for Spinners contains the comments for understanding how to make the selector lighter or change the selector if you wish.

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <!-- Estilo padrão para o spinner dropdown. -->
        <item name="android:dropDownSpinnerStyle">@style/CustomSpinnerStyle</item>
    </style>

    <!-- Aqui eu defino estilo para todos os spinners do meu app, que será estendido pelo estilo que está na tag "parent" abaixo. -->
    <style name="CustomSpinnerStyle" parent="@android:style/Widget.Holo.Spinner">
        <!-- Aqui eu poderia definir um custom spinner selector por exemplo. Mas preferi utilizar o padrão mesmo. <item name="android:background">@drawable/custom_spinner_selector</item> -->
    </style>

    <!--Este estilo aplica ao spinner o tema dark, ou seja, como o tema é DARK, as coisas terão as cores para se sobre sair ao escuro do tema.
        <style name="Widget.Holo.Spinner" parent="Widget.Spinner.DropDown">
            <item name="android:background">@android:drawable/spinner_background_holo_dark</item>
            <item name="android:dropDownSelector">@android:drawable/list_selector_holo_dark</item>
            <item name="android:popupBackground">@android:drawable/menu_dropdown_panel_holo_dark</item>
            <item name="android:dropDownVerticalOffset">0dip</item>
            <item name="android:dropDownHorizontalOffset">0dip</item>
            <item name="android:dropDownWidth">wrap_content</item>
            <item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item>
            <item name="android:gravity">start|center_vertical</item>
            <item name="android:disableChildrenWhenDisabled">true</item>
        </style>
    -->

    <!-- Se eu tivesse um tema claro e quisesse aplicar um tema escuro para o spinner, eu deveria estender deste estilo e não o acima.
        <style name="Widget.Holo.Light.Spinner" parent="Widget.Holo.Spinner">
        <item name="android:background">@android:drawable/spinner_background_holo_light</item>
        <item name="android:dropDownSelector">@android:drawable/list_selector_holo_light</item>
        <item name="android:popupBackground">@android:drawable/menu_dropdown_panel_holo_light</item>
        <item name="android:dropDownVerticalOffset">0dip</item>
        <item name="android:dropDownHorizontalOffset">0dip</item>
        <item name="android:dropDownWidth">wrap_content</item>
        <item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item>
    </style>
    -->

</resources>
    
04.06.2014 / 22:05