在菜单项中使用actionLayout时未调用onNavigationItemSelected方法。在ActionLayout上不调用两个水平线性布局onClick。无法找到通话方式?
MainActivity
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view sendMenuItem clicks here.
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
final Intent navigationIntent = new Intent(this, NavigationDrawerActivity.class);
if (item.getItemId()==R.id.extra){
item.getActionView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.nav_rateus:
navigationIntent.putExtra(NavigationDrawerActivity.NAVIGATION_DRAWER_KEY, NavigationDrawerActivity.RATE_US);
startActivity(navigationIntent);
break;
case R.id.logout:
//clear all data
clearObj();
AuthUI.getInstance().signOut(getApplicationContext());
break;
}
}
});
}
下面的ActionLayout xml代码。 logoutLayout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/nav_rateus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="@dimen/measure_26dp"
android:layout_height="@dimen/measure_26dp"
android:src="@drawable/rateus"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rate_us"/>
</LinearLayout>
<LinearLayout
android:id="@+id/logout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="@dimen/measure_26dp"
android:layout_height="@dimen/measure_26dp"
android:src="@drawable/logout"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/logout"/>
</LinearLayout>
导航抽屉菜单如下所示。 navigation_drawer.xml
<item
android:id="@+id/extra"
android:title=""
app:actionLayout="@layout/logout_layout"/>