相关疑难解决方法(0)

使用按钮背景颜色为我的按钮添加涟漪效果?

我创建了一个按钮,我想为该按钮添加涟漪效果!

我创建了一个按钮bg XML文件:(bg_btn.xml)

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#00FF00" android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#000000" />
</shape>
Run Code Online (Sandbox Code Playgroud)

这是我的涟漪效应文件:(ripple_bg.xml)

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="#f816a463"
    tools:targetApi="lollipop">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#f816a463" />
        </shape>
    </item>
</ripple>
Run Code Online (Sandbox Code Playgroud)

这是我想要添加涟漪效果的按钮:

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="173dp"
android:textColor="#fff"
android:background="@drawable/ripple_bg"
android:clickable="true" />
Run Code Online (Sandbox Code Playgroud)

但添加涟漪效果后按钮背景是透明的,只有在点击时才会显示按钮,如下所示:

点击之前

点击

但我需要按钮背景颜色和涟漪效果,我在Stack Overflow的不同博客中发现了一些此代码,但它仍然无效!

android android-layout android-drawable rippledrawable

107
推荐指数
10
解决办法
11万
查看次数

如何在“材质组件”的“材质按钮”中设置渐变背景?

我一直在尝试从Android的Material Components中的Material Button中设置渐变背景,但是它不起作用。那么,如何在“材质”按钮中设置渐变背景?

android gradient material-components-android

3
推荐指数
4
解决办法
1040
查看次数