Android: How to Make A Drawable Selector

You can add this in Android Studio, use Right click on project structure -> New -> Drawable resource file. It should look like this: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_enabled=”false” android:drawable=”@drawable/cell_top_selected” /> <item android:drawable=”@drawable/cell_top” /> </selector>

How to use selector to tint ImageView?

If you’re in API 21+ you can do this easily in XML with a selector and tint: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_activated=”true”> <bitmap android:src=”https://stackoverflow.com/questions/19500039/@drawable/ic_settings_grey” android:tint=”@color/primary” /> </item> <item android:drawable=”https://stackoverflow.com/questions/19500039/@drawable/ic_settings_grey”/> </selector>

Android customized button; changing text color

Create a stateful color for your button, just like you did for background, for example: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– Focused and not pressed –> <item android:state_focused=”true” android:state_pressed=”false” android:color=”#ffffff” /> <!– Focused and pressed –> <item android:state_focused=”true” android:state_pressed=”true” android:color=”#000000″ /> <!– Unfocused and pressed –> <item android:state_focused=”false” android:state_pressed=”true” android:color=”#000000″ /> <!– Default color –> <item android:color=”#ffffff” /> … Read more

Android selector & text color

I got by doing several tests until one worked, so: res/color/button_dark_text.xml <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_pressed=”true” android:color=”#000000″ /> <!– pressed –> <item android:state_focused=”true” android:color=”#000000″ /> <!– focused –> <item android:color=”#FFFFFF” /> <!– default –> </selector> res/layout/view.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent” > <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”EXIT” android:textColor=”@color/button_dark_text” /> </LinearLayout>