问题
The ripple effect I have given to the background of the button is not working.It just switches the color.The device version is 5.1.1.Please help me!!!
ripple.xml:
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white"> <!-- ripple color -->
<item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->
</ripple>
回答1:
Have you tried like this
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="New Button" />
But here you cant change ripple effect color
回答2:
Here's an example on how to set the normal background color when using ripple tag.
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white"> <!-- ripple color -->
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_blue_bright" /> <!-- normal color -->
</shape>
</item>
</ripple>
回答3:
The proper way to do is like this -
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#66ef5350"
> <!-- ripple color -->
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#66ef5350" />
<corners android:radius="2dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#ef5350" />
<corners android:radius="2dp"/>
</shape>
</item>
</ripple>
You can change the color as per your requirements.
来源:https://stackoverflow.com/questions/46014186/android-ripple-for-button-not-working