Button的单击变色+button上面图片下边文字+圆角

简单来说就是自定义一个drawable。

有两种情况。

第一种:

单击时变色,不单击则原色:(pressed是单击,focused是获取焦点,selected是被选择的根据需要更改)

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/arr_down_gray" android:state_focused="false"/>
<item android:drawable="@drawable/arr_down_gray_click" android:state_pressed="true"/>
<item android:drawable="@drawable/arr_down_gray_click" android:state_focused="true"/>
<item android:drawable="@drawable/arr_down_gray_click" android:state_selected="true"/>
</selector>

@drawable时可以是圆角的文件:

圆角也是在drawable放置

<?xml version="1.0" encoding="utf-8"?>

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

    <corners
            android:bottomLeftRadius="5dp"
            android:topLeftRadius="5dp"/>

    <stroke android:color="#1E4A71"
        android:width="1dp"/>

    <solid android:color="#17293C"/>
</shape>

 

第二种:

选择则改变,不选择则默认:

如:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/nav_waybill"
          android:state_checked="false"/>
    <item android:drawable="@drawable/nav_waybill_cur"
            android:state_checked="true"/>
</selector>

 

 

----------------------------------------------------------分割线---------------------------------------------------------------

 

对于button上面图片下边文字可以用以下方式:

<Button
                android:id="@+id/waybill_button"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:button="@null"
                android:layout_weight="1"
                android:checked="true"
                android:drawableTop="@drawable/nav_waybill_bg"
                android:text="运单"
                android:textColor="@drawable/nav_text_color"
                android:gravity="center"
                android:background="#152D43"
                />

然后text的变色可以加下面的drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#fff"
          android:state_checked="false"/>
    <item android:color="#0397D8"
          android:state_checked="true"/>
</selector>

对于图片放置的问题,可以先从drawable-xxhdpi文件夹实现,然后开不同分辨率下的效果,有时不用准备一套图片就能实现。

图片如下:

3KB~A~R86VZCL[}D3)M0_OG

转载于:https://www.cnblogs.com/ccddy/p/3991189.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值