Changing text color in edit box of android according to the focus
I am using the below xml file to change the color of editbox. But i would like to know how to change the text color in the editbox according to the focus. If the editbox is focussed i like to change the text color to black and when it is not focussed i like to change the color to white.
How do i implement this in the xml file? Any help would be really useful for me in learning the android drawable resources.
<?xml versio开发者_运维问答n="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<shape>
<gradient
android:endColor="#FFFFFF"
android:startColor="#FFFFFF"
android:angle="90" />
<stroke
android:width="3dp"
android:color="#0f0f0f" />
<corners
android:radius="10dp" />
</shape>
</item>
<item android:state_focused="false">
<shape>
<gradient
android:endColor="#000000"
android:startColor="#000000"
android:angle="90" />
<stroke
android:width="3dp"
android:color="#151515" />
<corners
android:radius="10dp" />
</shape>
</item>
you should use ColorStateList instead of State List.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ffff0000" /> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff" /> <!-- focused -->
<item android:color="#ff000000" /> <!-- default -->
then just assign this state list to textColor property.
I think you're looking for a State List.
精彩评论