我是这里的初学者!
我的导航抽屉有问题。
下次单击任何按钮时,该按钮均不可见
视频: https://drive.google.com/open?id=1PCGwofa6NPHh3P5Hqwuut1tG0qphEfUi
这是在Android上使用的导航视图。
public class ActionBar {
private AppCompatActivity activity;
private DrawerLayout drawerLayout;
//private AlertDialog alertDialog;
public ActionBar(AppCompatActivity activity) {
this.activity = activity;
//drawerLayout = activity.findViewById(R.id.drawer_layout);
configureToolbar();
configureNavigationDrawer();
}
private void configureToolbar() {
Toolbar toolbar = activity.findViewById(R.id.toolbar);
activity.setSupportActionBar(toolbar);
android.support.v7.app.ActionBar actionbar = activity.getSupportActionBar();
if (actionbar != null) {
actionbar.setHomeAsUpIndicator(R.drawable.ic_menu);
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setTitle("");
}
toolbar.findViewById(R.id.cast).setOnClickListener(new Cast());
}
private void configureNavigationDrawer() {
drawerLayout = activity.findViewById(R.id.drawer_layout);
NavigationView navView = activity.findViewById(R.id.navigation);
navView.setNavigationItemSelectedListener(menuItem -> {
switch (menuItem.getItemId()) {
case R.id.nav_radio:
//CODE
break;
case R.id.nav_recordings:
//CODE
case R.id.nav_settings:
//CODE
break;
case R.id.nav_share:
//CODE
break;
case R.id.nav_about:
//CODE
break;
case R.id.nav_feedback:
//CODE
break;
case R.id.nav_exit:
activity.finish();
break;
}
activity.overridePendingTransition(0, 0);
drawerLayout.closeDrawer(GravityCompat.START);
return true;
});
navView.setItemBackgroundResource(R.drawable.navigation_drawer_item_color);
}
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
drawerLayout.openDrawer(GravityCompat.START);
return true;
}
return true;
}
public boolean onCreateOptionsMenu(Menu menu) {
activity.getMenuInflater().inflate(R.menu.empty_menu, menu);
return true;
}
private class Cast implements View.OnClickListener {
@Override
public void onClick(View v) {
Toast.makeText(activity, R.string.not_yet, Toast.LENGTH_SHORT).show();
}
}
}
///////////////////////////////////////////////// ////////////////////
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@color/selected" />
<item android:state_selected="true" android:drawable="@color/selected" />
<item android:state_pressed="true" android:drawable="@color/pressed" />
<item android:state_focused="true" android:drawable="@color/pressed" />
<item android:state_active="true" android:drawable="@color/selected" />
<!--<item android:drawable="@color/pressed" />-->
</selector>
///////////////////////////////////////////////// //////////////////// activity_main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!--<include layout="@layout/logo"/>-->
<!--<include layout="@layout/bottom_controls"/>-->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<!-- For fragments -->
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/logo"/>
<include layout="@layout/bottom_controls" />
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_items">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
所单击的按钮不应消失