有背景颜色和波纹作用的机器人按钮

前端之家收集整理的这篇文章主要介绍了有背景颜色和波纹作用的机器人按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 Android按钮,我想给它一个背景颜色和两个涟漪效果

我的涟漪xml如下.

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="#BDA0CB"
    tools:targetApi="lollipop">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#BDA0CB" />
        </shape>
    </item>
</ripple>

我的按钮是

<Button android:id="@+id/Button_activity_login_ViewProfile" style="?android:textAppearanceSmall"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_marginTop="16dp" android:text="Save"
        android:textStyle="bold"
        android:layout_marginLeft="@dimen/margin_left"
        android:layout_marginRight="@dimen/margin_right"
        android:textColor="#ffffffff"
        android:fontFamily="sans-serif"
        android:background="#ff7e51c2" />

要给出涟漪效果,我必须删除背景颜色……有没有办法可以保留两者.

解决方法

这可以通过在你的ripple.xml中添加android:drawable来实现.

首先将其添加到color.xml中.假设#ff7e51c2是你想要按钮的背景颜色.

...
<color name="btn_bg_color">#ff7e51c2</color>
....

然后为按钮背景创建一个drawable(/drawable/btn_bg.xml):

<?xml version="1.0" encoding="utf-8"?><shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="2dp" />
<solid
    android:color="@color/btn_bg_color" />
</shape>

然后在ripple.xml中使用drawable:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item android:drawable="@drawable/btn_bg"/>
</ripple>
原文链接:https://www.f2er.com/android/309492.html

猜你在找的Android相关文章