更改CardView阴影颜色 [英] Changing CardView shadow color

查看:333
本文介绍了更改CardView阴影颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题被问了很多次,但是我仍然没有找到解决这个问题的好方法。



为什么我需要这样做?好吧,因为我和我的团队开发的项目具有iOS风格。



我尝试了什么?






  1. 请参见 outlineAmbientShadowColor outlineSpotShadowColor spotShadowAlpha ambientShadowAlpha 属性以获取详细信息。不幸的是,这可能从API 28开始。



    对于较低的API,尼克分享了一个要点。结果如下:





    在API 21上运行



    此技术未直接与 CardView 相关,可以应用于任何 View


    This question was asked on SO many times, but still I didn't find a good solution for this problem.

    Why do I need this to do? Well because project me and my team develops has iOS style.

    What did I try?

    1. 9.pathch shadow generator but 9.pathes are essentially pngs and it gives me no flexibility and if I'll use this approach I should edit margins everywhere.
    2. Carbon library it supports custom shadows and they get drawn outside of view borders, but there is issue regarding rounded rectangles, when library doesn't draw shadow for rounded corners.
    3. using old CardView implementation and overriding its shadow color, but it gets drawn inside of card bounds, so it isn't option.

    So is there a way to change shadow color of CardView with minimum edits of all layout files and with drawing shadow outside of the view like original CardView does?

    解决方案

    Consider this thread in twitter, where Nick Butcher talks about how to implement the feature:

    See outlineAmbientShadowColor, outlineSpotShadowColor, spotShadowAlpha and ambientShadowAlpha attributes for details. Unfortunately, that's possible from API 28 onwards.

    For lower APIs Nick has shared a gist. Here's the result:

    Running on API 21

    This technique isn't directly connected to CardView, it can be applied to any View.

    这篇关于更改CardView阴影颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆