相关疑难解决方法(0)

如何在选择器中设置按钮的文本样式?

按钮选择器允许为按钮的每个状态定义背景,但是如何为每个状态定义按钮的文本样式?我的目标是在禁用时使按钮变灰.所以我为按钮的禁用状态设置了一个灰色的背景,但我发现灰色文本的唯一方法是在禁用按钮时动态更改它的颜色...

有人可以帮忙吗?

谢谢

<style name="srp_button" parent="@android:style/Widget.Button">
    <item name="android:background">@drawable/btn_default</item>
    <item name="android:textColor">#ffffff</item> <!-- How to specify different color for different state? -->
    <!-- more stuff -->
</style>
Run Code Online (Sandbox Code Playgroud)

绘制/ btn_default.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_enabled="true"><shape>
            <solid android:color="@color/pink" />
            <corners android:radius="6dp" />
        </shape></item>
    <item><shape>
            <solid android:color="#000000" />
            <corners android:radius="6dp" />
        </shape></item>

</selector>
Run Code Online (Sandbox Code Playgroud)

android button

24
推荐指数
1
解决办法
2万
查看次数

更改已禁用按钮的文本颜色

我有一个这样的按钮:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Hello"
    android:textColor="@color/primary"
    android:background="@drawable/button"
    />
Run Code Online (Sandbox Code Playgroud)

可绘制的button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false"
        android:drawable="@drawable/button_disabled" />
    <item android:drawable="@drawable/button_default" />
</selector>
Run Code Online (Sandbox Code Playgroud)

可绘制的button_disabled.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/white"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

我还想在禁用按钮时更改按钮的文本颜色.如何为每个州指定不同的文字颜色?

android android-layout android-xml

6
推荐指数
0
解决办法
6115
查看次数

禁用 editText 但使用不同的颜色

<EditText
    android:id="@+id/myEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:enabled="false" >
</EditText>
Run Code Online (Sandbox Code Playgroud)

我有上面的编辑文本被禁用。我只从其他地方获取值并将其插入那里,用户无法在其中键入。但是,处于禁用形式时编辑文本的颜色太灰色,有时用户不可见。我更喜欢它看起来是黑色的。是否有任何我不知道的基本功能可以在禁用模式下更改编辑文本的颜色?任何其他解决办法也可以正常工作。

user-interface android android-edittext

5
推荐指数
2
解决办法
6716
查看次数