Android ripple for button not working

落花浮王杯 提交于 2019-12-11 03:35:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!