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

  • 相关阅读:
    .Net开发笔记(二十一) 反射在.net中的应用
    .Net开发笔记(二十)创建一个需要授权的第三方组件
    .Net开发笔记(十九) 创建一个可以可视化设计的对象
    .net开发笔记(十八) winform中的等待框
    .Net开发笔记(十七) 应用程序扩展
    java连接https时禁用证书验证.
    How to disable SSL certificate checking with Spring RestTemplate?(使用resttemplate访问https时禁用证书检查)
    webpack打包调试react并使用babel编译jsx配置方法
    动态改变spring定时任务执行频率
    在java代码中,用xslt处理xml文件
  • 原文地址:https://www.cnblogs.com/ccddy/p/3991189.html
Copyright © 2011-2022 走看看