android - 如何让 Android TextView 看起来像是被禁用了?

标签 android styles

我希望能够为任何 TextView 提供与禁用时相同的外观。 目前,我使用的样式继承了 TextAppearance 并添加了灰色文本颜色,但我更喜欢使用可以与任何主题完美配合的内置样式。

最佳答案

定义一个带有禁用颜色的选择器,并在这样的布局中使用它

在颜色文件中(例如 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>

然后在你的布局中:

<TextView
    android:text="whatever text you want"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/example" />

关于android - 如何让 Android TextView 看起来像是被禁用了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10836381/

相关文章:

android - 有没有办法获取android "history"系统日志?

android - 在 styles.xml 中定义工具栏渐变

html - 如何使用伪类:before/:after?

android - 创建自定义样式会导致应用程序崩溃

WPF TabControl 模板 + ItemContainerStyle

android - 如何取消DelayedConfirmationView?

android - 什么是 keycharmap 文件?为什么我收到 'cant open keycharmap file' 警告?

android - R 无法解析为新项目中的变量

java - Android - 一段时间后获取位置

html - 如何着色未读链接phpBB