我有一个
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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。