Android ripple background color -
i using ripple effect on navigation drawer. have set , applied listview:
<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_activated="true" android:drawable="@color/black_200" />      <item android:state_pressed="true" android:color="@color/black_200">         <ripple android:color="@color/black_400" />     </item>      <item android:drawable="@color/white" /> </selector>   i want ripple background remain same normal activated state. when define color same activated state, gets darker , ripple bubble gets more dark. how can color background same activated state , ripple bubble color told be?
you can control colour of rippledrawable doing following:
rippledrawable rippledrawable = (rippledrawable)view.getbackground(); // assumes bg rippledrawable  int[][] states = new int[][] { new int[] { android.r.attr.state_enabled} }; int[] colors = new int[] { color.blue }; // sets ripple color blue  colorstatelist colorstatelist = new colorstatelist(states, colors); rippledrawable.setcolor(colorstatelist);   or, via xml:
<?xml version="1.0" encoding="utf-8"?> <ripple     xmlns:android="http://schemas.android.com/apk/res/android"     android:color="#ffff0000"> <!-- ripple red -->      <!-- normal bg color light grey -->     <item>         <color android:color="#ffdddddd" />     </item>      <!-- make sure ripple doesn't exceed bounds -->     <item android:id="@android:id/mask">         <shape android:shape="rectangle">             <solid android:color="?android:coloraccent" />         </shape>     </item> </ripple>   edit
after seeing @i.shadrin's answer below, must admit it's simpler approach (using styles). if option you, recommend it.
Comments
Post a Comment