13

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.

Bastien Léonard
  • 60,478
  • 20
  • 78
  • 95

5 Answers5

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" />

enter image description here

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:

Android selector & text color

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
  • 2
    Answer 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
  • 3
    I 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