zoukankan      html  css  js  c++  java
  • Android Material适配 为控件设置指定背景色和点击波纹效果

    Android Material适配 为控件设置指定背景色和点击波纹效果,有需要的朋友可以参考下。



    大部分时候,我们都需要为控件设置指定背景色和点击效果 

    4.x以下可以使用selector,5.0以上需要带波纹效果,以下是实现该效果的方法。 

    比如实现Button的Material适配





    <Button
            android:text="TextView in CardView"
            android:layout_gravity="center"
            android:textSize="26sp"
            android:textColor="@android:color/white"
            android:clickable="true"
            android:background="@drawable/button_selector"
            android:padding="5dip"
            android:elevation="8dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


    1.创建drawable和drawable-v21两个资源文件夹



    2.在drawable中创建一个button_selector.xml的文件,设置需要的点击效果,使用selector实现。





       <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" android:state_pressed="false"/>
        <item android:drawable="@color/grey" android:state_pressed="true"/>
        <item android:drawable="@android:color/white"/>
    </selector>


    3.在drawable-v21中创建一个与drawable中同名的button_selector.xml的文件,设置需要的点击效果,ripple是Material的波纹效果。





    <?xml version="1.0" encoding="utf-8"?>
    <ripple
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/grey">//点击时波纹的颜色
         <item android:drawable="@android:color/white"/>//未点击时控件的颜色
    </ripple>


    完成。

  • 相关阅读:
    VC++删除浮动工具条中“关闭”按钮
    automation无法创建对象
    SQL Server 不产生日志
    收缩数据文件
    VB DoEvents用法
    Sql Server添加用户
    Winsock错误代码一览表
    监控数据库性能的sql
    数据库日志文件清理脚本
    VB 中资源文件的多种使用技巧
  • 原文地址:https://www.cnblogs.com/qianyukun/p/5857168.html
Copyright © 2011-2022 走看看