Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of a disabled spinner Android

When I disable my spinner it's dispalyed a text with an alpha so texte become a little not visible, my question how I can change this color ? PS : I don't need to change the color of the spinner's texte.

like image 446
NizarETH Avatar asked Jan 18 '17 11:01

NizarETH


2 Answers

Create a color folder in res and create a color state my_text_color.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/disableColor" android:state_enabled="false"/>
    <item android:color="@color/enableColor"/>
</selector>

and your textview look like

  <TextView
    android:textColor="@color/my_text_color"

In adapter you need to inflate the layout that contain the Textview. Inside your adapter constructor, send the id of textview also

public CustomAdapter(Activity context,int resouceId, int textviewId, List<RowItem> list){

        super(context,resouceId,textviewId, list);
        flater = context.getLayoutInflater();
    }

call it by

CustomAdapter adapter = new CustomAdapter(MainActivity.this,
                R.layout.listitems_layout, R.id.title, rowItems);
like image 106
Salauddin Gazi Avatar answered Sep 27 '22 20:09

Salauddin Gazi


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/disabled_color"/>
    <item android:color="@color/normal_color"/>
</selector>

<EditText
    android:id="@+id/customEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:enabled="false"
    android:text="Hello!"
    android:textColor="@drawable/edit_text_selector" />

// first code used in drawable/edit_text_selector.xml

like image 32
Vicky Mahale Avatar answered Sep 27 '22 20:09

Vicky Mahale