更改Android中禁用按钮的颜色 [英] Change the color of a disabled button in android

查看:122
本文介绍了更改Android中禁用按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以通过样式或其他形式来更改android中已禁用按钮的颜色?

Is there a way to change the color of a disabled button in android through styles or some other form ?

我目前有以下情况,

drawable/button_default.xml

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

drawable/button_default_shape.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/button_default_background"/>
    <corners android:radius="3dp"/>
</shape>

values/styles.xml

<style name="AppTheme.Button">
    <item name="android:background">@drawable/button_default</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:paddingTop">10dp</item>
    <item name="android:paddingBottom">10dp</item>
    <item name="android:focusable">true</item>
    <item name="android:clickable">true</item>
    <item name="android:gravity">center</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">17sp</item>
    <item name="android:textAppearance">@style/CustomFontAppearance</item>
</style>

推荐答案

在这些状态下,您必须为不同的可绘制对象使用选择器.

You'll have to use a selector for different drawables in those states.

您可以创建这样的选择器:

You can create a selector like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/your_enabled_drawable" android:state_enabled="true" />
    <item android:drawable="@drawable/your_disabled_drawable" android:state_enabled="false" />
    <!-- default state-->
    <item android:drawable="@drawable/your_enabled_drawable" />
</selector>

这篇关于更改Android中禁用按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆