Android控件阴影颜色调整示例

所属分类: 软件编程 / Android 阅读数: 43
收藏 0 赞 0 分享

CardView在设置阴影的效果上来讲,确实是蛮不错的。

但是涉及到变更阴影颜色这个需求,就不是太好操作。

然后就自己描边画了一个阴影效果,分享,支持任何颜色。

效果:

xml-selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_enabled="true">
    <layer-list>
      <item android:right="1dp" android:top="2dp">
        <layer-list>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#15cbf2e0" />
              <padding android:bottom="6px" android:left="6px" android:right="6px" android:top="6px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#16cbf2e0" />
              <padding android:bottom="4px" android:left="4px" android:right="4px" android:top="4px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#17cbf2e0" />
              <padding android:bottom="2px" android:left="2px" android:right="2px" android:top="2px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#18cbf2e0" />
              <padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#19cbf2e0" />
              <padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#20cbf2e0" />
              <padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#21cbf2e0" />
              <padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#22cbf2e0" />
              <padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
            </shape>
          </item>
          <item>
            <shape android:shape="rectangle">
              <solid android:color="#23cbf2e0" />
              <padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
            </shape>
          </item>
        </layer-list>
      </item>
      <item>
        <shape android:shape="rectangle">
          <solid android:color="@color/white" />
        </shape>
      </item>
    </layer-list>
  </item>
</selector>

关于描边的大小什么的,都可以自己设置,颜色也一样。都自己随意。

使用起来也是非常简单,

android:background="@drawable/lay_back"

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

Android实现信号强度监听的方法

这篇文章主要介绍了Android实现信号强度监听的方法,是Android手机中很常见的一个实用功能,需要的朋友可以参考下
收藏 0 赞 0 分享

Android实现Activity界面切换添加动画特效的方法

这篇文章主要介绍了Android实现Activity界面切换添加动画特效的方法,非常实用的技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中Dialog去黑边的方法

这篇文章主要介绍了Android中Dialog去黑边的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Qt for Android开发实例教程

这篇文章主要介绍了Qt for Android开发的方法,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发之时间日期操作实例

这篇文章主要介绍了Android开发之时间日期操作,是Android程序开发中常见的一个功能,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发之时间日期组件用法实例

这篇文章主要介绍了Android开发之时间日期组件用法,主要介绍了TimePicker和DatePicker组件,对于Android程序开发有不错的借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发之获取网络链接状态

这篇文章主要介绍了Android获取网络链接状态的方法,主要是通过ConnectivityManager类来完成的,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发之广播机制浅析

这篇文章主要介绍了Android开发之广播机制浅析,主要包括了发布、接收及配置广播的实例,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发之登录验证实例教程

这篇文章主要介绍了Android开发之登录验证实现方法,包括发送数据、服务器端验证、配置文件等,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发之注册登录方法示例

这篇文章主要介绍了Android开发的注册登录方法,是针对Android程序设计中版本兼容性的进一步完善,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多