2

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>
jobin
  • 1,311
  • 2
  • 21
  • 42
  • I don't see anything wrong in above xml. You may try to change ripple syntax by create 2 items with "@android:id/mask" and "@android:id/content" as it might be a bug related to a specified devices. Also if your project is supporting lower than 5.0, you may try Analyze APK to see if the apk was generates with the correct resource in the folder. – vsatkh Sep 02 '17 at 13:55

3 Answers3

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

Navneet Krishna
  • 4,667
  • 5
  • 21
  • 40
  • 1
    Why use "?attr/selectableItemBackground". Inspite of that we assign the @drawable/ripple – jobin Sep 02 '17 at 13:20
  • @jobin "?attr/selectableItemBackground" to your view's foreground attribute if it already has a background along with android:clickable="true" – AskNilesh Sep 02 '17 at 13:35
  • for more information check [this link](https://stackoverflow.com/questions/40008609/add-ripple-effect-to-my-button-with-button-background-color) add the "?attr/selectableItemBackground" to your view's foreground attribute if it already has a background along with android:clickable="true" – AskNilesh Sep 02 '17 at 13:35
0

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>
João Magalhães
  • 2,275
  • 2
  • 11
  • 16
0

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.

Aman Verma
  • 2,465
  • 4
  • 21
  • 41