Android text view color doesn't change when disabled

后端 未结 1 1000
醉酒成梦
醉酒成梦 2020-12-01 09:56

When I call setEnabled(false) for a TextView object the text color doesn\'t change. I expected it will be changed to gray. If I remove the line of

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 10:40

    I think what's happening is that since you're overriding the default textcolor it isn't inheriting the other textcolor styles. Try creating a ColorStateList for it and setting the textColor attribute to it instead of to a color.

    In a color file (eg res/color/example.xml):

    
    
        
        
    
    

    then in your layout:

    
    

    Note, I haven't done this in a while and I'm typing a lot of this from memory, so it may need a little tweaking. The ColorStateList docs (linked above) have a more fleshed-out example for the color XML file.

    0 讨论(0)
提交回复
热议问题