Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an Android text view look like it's disabled?

Tags:

android

styles

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.

like image 560
Bastien Léonard Avatar asked May 31 '12 15:05

Bastien Léonard


People also ask

How do I turn off text view on Android?

It's possible to preserve both the style of the view and the scrolling behaviour. To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library. If you want to replicate this behaviour without the library, check out the source code for this small method.

What is editable text in Android?

This is the class for text whose content and markup can both be changed. This is the interface for text whose content and markup can be changed (as opposed to immutable text like Strings). If you make a DynamicLayout of an Editable, the layout will be reflowed as the text is changed.

What is text view in mobile application?

Android App Development for Beginners A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.


1 Answers

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" />
like image 198
Hybrid Developer Avatar answered Oct 05 '22 03:10

Hybrid Developer