gpt4 book ai didi

android - 如何为按钮添加模糊的阴影?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:05 25 4
gpt4 key购买 nike

我需要为我的按钮添加模糊的阴影:

enter image description here

我尝试使用 layer-list xml drawable 创建背景,但它看起来不像模糊。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Drop Shadow Stack -->
<item>
<shape>
<corners android:radius="45dp" />
<padding
android:bottom="2dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />

<stroke
android:width="6dp"
android:color="#007879E8" />

</shape>
</item>
////// 10 more items
<item>
<shape>
<corners android:radius="45dp" />
<padding
android:bottom="2dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />

<stroke
android:width="6dp"
android:color="#177879E8" />


</shape>
</item>

<!-- Background -->
<item>
<shape>
<corners android:radius="45dp" />
<stroke
android:width="2dp"
android:color="@color/main_purple_text_color" />
</shape>
</item>

</layer-list>

我还尝试在带有模糊 png 的按钮后面使用背景元素,但它使用了很多资源,我无法创建选择器来在悬停或单击时更改背景。

我需要为按钮设置单个背景文件,并使用选择器在悬停/单击时更改模糊和渐变。有什么想法可以用 Android SDK 实现这样的效果吗?

更新 1

感谢大家的回答,但我不是在问如何创建渐变。我已经这样做了。我需要创建模糊的阴影。

最佳答案

好吧,我找到了解决方案:我们需要通过这个 generator 创建带有模糊阴影的 9.png并将其传递给包含按钮背景渐变的可绘制图层列表:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/blurred_9_path_png" />
<item>
<shape android:shape="rectangle" android:padding="10dp">
<corners android:radius="45dp" />
<gradient
android:angle="45"
android:endColor="@color/facebook_btn_fill_grad2"
android:startColor="@color/facebook_btn_fill_grad1"
android:type="linear" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
</item>

</layer-list>

之后我们可以使用具有不同 9.path 模糊阴影的 drawables 来创建选择器。

关于android - 如何为按钮添加模糊的阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47674828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com