i++

プログラム系のメモ書きなど

Android : NavigationView の headerLayout の RippleEffect を消す

クリックイベントを設定していない、ディスプレイ用のヘッダーでもクリック時に RippleEffect が表示されます。

これを消すには、headerLayout に設定したレイアウトの親要素に android:id を設定し、headerLayout に setOnClickListener を付ければ OK。

逆に、setOnClickListener をつけて本当に何かアクションを起こしたい場合には、Ripple Effect が消えてしまうのはどうなんだろう?という気もしますが…。

headerLayout に設定する layout の例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/nagivation_header_root"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="96dp">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="16dp"
        android:src="@mipmap/ic_launcher"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="16dp"
        android:text="@string/app_name"
        android:textSize="24dp"/>
</LinearLayout>
RippleEffect を消すコード
findViewById(R.id.nagivation_header_root).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    }
});

Issue 176400 - android - Ripple effect visible under the colored headerLayout of NavigationView - Android Open Source Project - Issue Tracker - Google Project Hosting