简体   繁体   English

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

[英]navigation Screen opening when i click on button but its not closing again when i click it again

navigation Screen opening when i click on button but its not closing again when i click it again.当我点击按钮时导航屏幕打开,但当我再次点击它时它不会再次关闭。 below is my code.下面是我的代码。 this is my java code:这是我的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();
 }

try this way , i hope works with you.试试这种方式,我希望对你有用。

@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);
    }

the listener听者

    @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;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我单击“暂停”按钮时,它暂停了,但是当我再次单击“播放”按钮时,它从头开始播放歌曲 - When I click pause button it paused but when i clicked again play button , it starts the song from start 当我多次单击底部导航项时,片段再次加载 - When I click the bottom navigation item more times the fragment loading again 当再次点击按钮显示激励广告时,没有广告显示 - When click again on button to show rewarded ad no ad is showing 当我单击 AlertDialog 项目时,关闭并再次打开警报对话框时,单选组不会保持打开状态 - When I click on AlertDialog item, the radio group not stay ON when close and open alert dialog again 单击按钮再次运行程序? - Running a program again on button click? 单击按钮时显示叠加层,并在使用 Swing 执行操作后再次消失 - Display an overlay when a button is click and disappear again when the action has been performed using Swing 按下“主页”按钮后,从点击图标应用程序再次启动我的活动后,我的活动不会重新加载 - After Home button pressed, my Activity not reload when launch it again from click icon app 单击按钮后如何在JSON中获取ID并想在post方法中再次发送该ID - How i have to get the id in JSON after click the button and want to send that id again in post method 如何使重置按钮在单击后自动再次播放? - how to make reset button automatically play again when its clicked? 当我单击否或取消选项时,为什么此JOptionPane程序没有关闭? - Why is thisJOptionPane program not closing when I click the no or cancel options?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM