I'd like to be able to give any text view the same aspect as if it was disabled.
Currently I am using a style that inherits TextAppearance
and adds a gray text color, but I'd prefer using something built-in that would work flawlessly with any theme.
Asked
Active
Viewed 2.0k times
13

Bastien Léonard
- 60,478
- 20
- 78
- 95
-
you can set android:background="#666" and text android:textColor="#333" which looks like disable textview. – MAC May 31 '12 at 15:27
-
@gtumca-MAC: do you mean that I should customize the colors to look disabled, or that providing no values will make it look disabled? – Bastien Léonard May 31 '12 at 15:32
-
Did you ever find a solution to this? – Andrew No Mar 22 '16 at 23:44
-
@AndrewNo No unfortunately. – Bastien Léonard Mar 24 '16 at 08:56
-
Possible duplicate of [Android text view color doesn't change when disabled](https://stackoverflow.com/questions/1342410/android-text-view-color-doesnt-change-when-disabled) – Fanglin Mar 28 '18 at 21:46
5 Answers
18
define a selector with a disable like color and use it in layouts like this
In a color file (eg res/color/example.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/disabled_color" />
<item android:color="@color/normal_color"/>
</selector>
then in your layout:
<TextView
android:text="whatever text you want"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/example" />

Hybrid Developer
- 2,320
- 1
- 34
- 55
0
<TextView
android:id="@+id/textView1"
android:background="#666"
android:textColor="#333"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
you can set android:background="#666"
and text android:textColor="#333" which looks like disable textview.
or any other combination of colors

MAC
- 15,799
- 8
- 54
- 95
0
This may be what you are looking for:
Basically, you have to use a selector as a color and then define a style that applies that text color.

Community
- 1
- 1

Gerardo Contijoch
- 2,421
- 5
- 20
- 29
0
android:alpha="0.33"

Doron Ben-Ari
- 443
- 3
- 12
-
2Answer needs supporting information Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – moken Jul 21 '23 at 11:46
-3
just try this
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:enabled="false" <--- Put this
android:textAppearance="?android:attr/textAppearanceLarge" />

Chintan Raghwani
- 3,370
- 4
- 22
- 33
-
3I want to be able to be able to use “normal” events (long-press in my case), so IIRC this won't work. As I said in my question, I just want the “look” of a disabled text view. – Bastien Léonard May 31 '12 at 15:30