Articles → Android → Color State List Resources In Android
Color State List Resources In Android
What Is Color State List Resource?
How To Add A New File?
- Right-click on the color folder.
- Go to New → Color resource file.
Click to Enlarge
- Following window will appear. Enter the file name and click on Ok.
Click to Enlarge
Adding Selector
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<!--pressed-->
<item android:state_pressed="true" android:color="#FF0000"></item>
<!-- default -->
<item android:color="#228B22"/>
</selector>
Add Selector In Button
<Button
android:id="@+id/button11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:textColor="@color/color_one" />
Click to Enlarge