How to grey out Views. Specifically an EditText?

2019-07-13 15:51发布

问题:

Hey guy's First of all thanks for reading this. I'm having trouble to find a way to change my EditText when I loose focus to it. I would like it to be greyed out when this happens, but I don't want it to be disabled because the user can touch it and edit the text later.

Anyone?

Greetings!

回答1:

You can set different colors to the text based on an OnFocusChangeListener

Another option is to set a style in xml. See this question for details: Android: change style when focused

To change the opacity, use setAlpha. In this answer I show it how to do it in an animation: Two questions about custom app ui's and AlphaAnimation