android-button背景可绘制不起作用 [英] android-button background drawable doesn't work

查看:90
本文介绍了android-button背景可绘制不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的xml drawbale代码,名称为btntheme.xml:

this is my xml drawbale code with the name of btntheme.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/customactionbartheme_btn_default_normal_holo_light" android:state_enabled="true" android:state_window_focused="false"/>
    <item android:drawable="@drawable/customactionbartheme_btn_default_disabled_holo_light" android:state_enabled="false" android:state_window_focused="false"/>
    <item android:drawable="@drawable/customactionbartheme_btn_default_pressed_holo_light" android:state_pressed="true"/>
    <item android:drawable="@drawable/customactionbartheme_btn_default_focused_holo_light" android:state_enabled="true" android:state_focused="true"/>
    <item android:drawable="@drawable/customactionbartheme_btn_default_normal_holo_light" android:state_enabled="true"/>
    <item android:drawable="@drawable/customactionbartheme_btn_default_disabled_focused_holo_light" android:state_focused="true"/>
    <item android:drawable="@drawable/customactionbartheme_btn_default_disabled_holo_light"/>

</selector>

我已将所有具有这些名称的图像放入drawable-hdpi文件夹中.

I've put all those images with the these names in the drawable-hdpi folder .

这是我的布局和按钮:

<Button
                android:id="@+id/button1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:background="@drawable/btntheme"
                android:textSize="@dimen/font_size_smallerButton" />

它不起作用,它根本不改变按钮主题吗?

it's not working , it doesn't change the button theme at all ?

您能帮我解决吗?

谢谢

推荐答案

尝试如下选择器:

<!-- Active tab -->
<item android:drawable="@drawable/customactionbartheme_btn_default_normal_holo_light" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Inactive tab -->
<item android:drawable="@drawable/customactionbartheme_btn_default_pressed_holo_light" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<!-- Pressed tab -->
<item android:drawable="@drawable/customactionbartheme_btn_default_pressed_holo_light" android:state_pressed="true"/>
<!-- Selected tab (using d-pad) -->
<item android:drawable="@drawable/customactionbartheme_btn_default_disabled_holo_light" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>

</selector>

有关更多详细指南,请访问

For more detail guidenc check out Custom Selector in Android

这篇关于android-button背景可绘制不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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