yourEditText.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (v == yourEditText) { if (hasFocus) { yourEditText..setTextColor(Color.RED); } else { } } } });
use a focus listener for this (button, etc.)
EDIT You must use XML and set the view background for this
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:color="yourDesiredcolorcode" /> <item android:state_focused="true" android:color="yourDesiredcolorcode" /> <item android:color="yourDesiredcolorcode" /> </selector>
Greetings
source share