0

Like i say. I don't know how to set everything in my spinner to white. Problem is in this image enter image description here

Like You see i have white and always black, with black background this button is not good visible.

Here is some code:

 <Spinner
        android:id="@+id/spinner_money"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="50$"
        android:textColor="@color/white"
        android:textSize="20sp" />

whats wrong guys?

Here i confgure spinner

private void configureSpinnerDataAndLogic() {
    String[] arraySpinner = new String[]{
            "50", "100", "150", "200", "250", "300", "400", "500"};

    ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(),
            android.R.layout.simple_list_item_1, arraySpinner);
    spinnerData.setAdapter(adapter);
    spinnerData.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            String text = spinnerData.getSelectedItem().toString();
            int temp = Integer.parseInt(text);
            text_profit.setText((temp * 2) + " $ " + "100%");
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}

Edited:

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:width="20dp"
        android:gravity="right"
        android:layout_centerVertical="true"
        android:height="20dp">
        <rotate
            android:fromDegrees="45"
            android:pivotX="135%"
            android:pivotY="15%"
            android:toDegrees="45">
            <shape android:shape="rectangle">
                <solid
                    android:color="@color/white" />
            </shape>
        </rotate>
    </item>
</layer-list>

enter image description here

Genehme
  • 69
  • 9

3 Answers3

1

You can set the spinners background color in xml like this:

android:background="@color/white"

and if you are using DropDown then in xml like this:

android:popupBackground="@color/your_color_for_items"

In case if you are using custom adapter, Please check this thread.

Community
  • 1
  • 1
Rohit
  • 2,646
  • 6
  • 27
  • 52
0

Try this code on your Spinner

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

So your final Spinner will look like this:

<Spinner
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="80dp"
    android:spinnerMode="dropdown"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:visibility="gone" />
Attaullah
  • 3,856
  • 3
  • 48
  • 63
0

It is very simple, actually. Create a theme that specifies this code in the styles.xml file:

<style name="MyPickerTheme" parent="Theme.MaterialComponents"> <item name="android:textColor">@android:color/white</item> </style>

Now just add ' android:theme="@style.MyPickerTheme" ' into your Spinner or any component.

NSV.
  • 65
  • 10