humble
humble

Reputation: 3

How to change the ripple color when an item is pressed in a navigation drawer

So I'm learning about how to incorporate the navigation drawer in my android app. I've successfully managed to incorporate it in my app. However, I cant find out how to change the ripple color when I press an item. I've used the following attribute

app:itemRippleColor="@color/purple"

to try and change the default grey ripple color. However it is not working

enter image description here

Can someone guide me? Also I would appreciate it if someone can tell me how to add custom animation when I press the item

Upvotes: 0

Views: 126

Answers (1)

Bob
Bob

Reputation: 2868

Answer 1:

In your navigation drawer menu layout file in menu item add the attribute itemRippleColor like below :

main_menu.xml

<item
    android:id="@+id/your_menu_item_id"
    android:title="Your Menu Item Title"
    app:itemRippleColor="@color/your_ripple_color" />

Answer 2:

menu_item_animation.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true">
      <objectAnimator
          android:propertyName="scaleX"
          android:duration="200"
          android:fromValue="1.0"
          android:toValue="1.1" />
      <objectAnimator
          android:propertyName="scaleY"
          android:duration="200"
          android:fromValue="1.0"
          android:toValue="1.1" />
  </item>
  <item>  </item>
</selector>

Navigation drawer menu layout xml :

<item
    android:id="@+id/your_menu_item_id"
    android:title="Your Menu Item Title"
    android:onClick="onMenuItemClick"  />

As you are using java currently :

public class MyActivity extends AppCompatActivity {

    public void onMenuItemClick(View view) {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.menu_item_press);
        view.startAnimation(animation);
        // Handle menu item selection logic here
    }
}

Upvotes: 0

Related Questions