[英]Android navigation drawer(provided by Android studio default)
当我按下导航菜单项的更改时,它的颜色为黄色,直到释放时一直按它为默认。我没有明确编写任何代码来设置这些设置。 我该如何停止?请帮忙。 这是我的代码。 主要布局
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:state_pressed="false"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_users"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_users"
app:menu="@menu/activity_users_drawer" />
</android.support.v4.widget.DrawerLayout>
导航视图菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view"
>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_satellite"
android:icon="@drawable/ic_satellite_black_24px"
android:title="@string/satelliteView" />
<item
android:id="@+id/nav_terrain"
android:icon="@drawable/ic_terrain_black_24px"
android:title="@string/terrain_nav" />
<item
android:id="@+id/nav_logout"
android:icon="@drawable/ic_power_settings_new_black_24px"
android:title="@string/logout_button" />
</group>
<item android:title="@string/communicateNavLine">
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_menu_share"
android:title="@string/shareNavButton"
/>
<item
android:id="@+id/nav_about_us"
android:icon="@drawable/ic_menu_send"
android:title="@string/aboutNavButton" />
</menu>
</item>
</menu>
Java代码-
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View header=navigationView.getHeaderView(0);
textViewNavHeader =(TextView)header.findViewById(R.id.text_nav_view);
当我点击第一个项目时-
之后放开就可以了
尝试添加自定义NavigationView.OnNavigationItemSelectedListener
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
// set item as selected to persist highlight
menuItem.setChecked(false);
// close drawer when item is tapped
mDrawerLayout.closeDrawers();
// Add code here to update the UI based on the item selected
// For example, swap UI fragments here
return true;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.