Android - Textview change color on changing of state

后端 未结 5 1965
滥情空心
滥情空心 2020-11-30 11:14

How can I apply color on the various states(focused, pressed, enabled) of the TextView?

I have already referred this: http://developer.android.com/reference/android/

5条回答
  •  北海茫月
    2020-11-30 11:57

    It's easy. Just intercept desired event and write smth like:

    TextView textView=(TextView)findViewById(R.id.myText);
    String s=getString(R.string.myText);
    SpannableString ss=new SpannableString(s);
    ss.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    textView.setText(ss);
    

提交回复
热议问题