Button自定义状态背景

API:APP Resource->ResourceType->Drawable->state list.

1.新建drawable目录下button.xml,修改对应状态图片。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/function_greenbutton_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/function_greenbutton_pressed" /> <!-- focused -->
    <item android:drawable="@drawable/function_greenbutton_normal" /> <!-- default -->
</selector>
2.在对应的layout xml下引用:

        <Button
            android:background="@drawable/button"
            android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:text="下一步"
	        android:layout_alignParentRight="true"
	        android:layout_alignParentBottom="true"
            />
完成。

最后,来看一下系统默认的button定义:

1.sdk->platform->values->style.xml:找到对应的button定义

    <style name="Widget.Button">
        <item name="android:background">@android:drawable/btn_default</item>
        <item name="android:focusable">true</item>
        <item name="android:clickable">true</item>
        <item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
        <item name="android:textColor">@android:color/primary_text_light</item>
        <item name="android:gravity">center_vertical|center_horizontal</item>
    </style>

2.可以看到,对应的backgroud为btn_default.xml,可以查看btn_default.xml定义进一步了解状态图片来源等信息。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值