zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    第七周psp
    【探路者】第三周立会报告6(总第18次)
    版本控制报告
    【探路者】第三周立会报告5(总第17次)
    【探路者】第三周立会报告4(总第16次)
    【探路者】第三周立会报告3(总第15次)
    #【探路者】第三周立会报告2(总第14次)
    【探路者】第三周立会报告1(总第13次)
    PSP
    【探路者】第二周立会报告6(总第12次)
  • 原文地址:https://www.cnblogs.com/ccddy/p/3991189.html
Copyright © 2011-2022 走看看