gpt4 book ai didi

java - 当我单击按钮时导航屏幕打开,但当我再次单击它时它不会再次关闭

转载 作者:行者123 更新时间:2023-12-01 18:39:17 25 4
gpt4 key购买 nike

当我单击按钮时导航屏幕打开,但当我再次单击它时它不会再次关闭。下面是我的代码。 这是我的java代码:

  toolbar = findViewById(R.id.maintoolbar);

toolbar.setTitleTextAppearance(this, R.style.ActionBarTitle);
// Sets the Toolbar to act as the ActionBar for this Activity window.
// Make sure the toolbar exists in the activity and is not null
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);

toolbar.setNavigationOnClickListener(new NavigationIconClickListener(
getBaseContext(),
findViewById(R.id.mainContainer),
new AccelerateDecelerateInterpolator(),
getApplicationContext().getResources().getDrawable(R.drawable.branded_menu), // Menu open icon
getApplicationContext().getResources().getDrawable(R.drawable.close_menu)));




bNavVu = findViewById(R.id.bottom_nav_vu);

final View activityRootView = findViewById(R.id.rootLayout);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);

int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
hideSystemUI();
}
}
});

if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.mainContainer, new CategoryFragment())
.commit();
}

最佳答案

试试这个方法,希望对你有用。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Menu 1");
setSupportActionBar(toolbar);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
Toolbar toggle = new Toolbar(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}

监听者

    @Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_menu1) {
// Handle the camera action
} else if (id == R.id.nav_menu2) {

} else if (id == R.id.nav_menu3) {

}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

关于java - 当我单击按钮时导航屏幕打开,但当我再次单击它时它不会再次关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59974884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com