当前位置:  开发笔记 > 编程语言 > 正文

Android Navigation Drawer Remains Highlighted

如何解决《AndroidNavigationDrawerRemainsHighlighted》经验,为你挑选了2个好方法。

I am able to navigate from Activity1 to Activity2 via my navigation drawer.

But upon pressing the back button at activity2, the option remains highlighted.

My Code in activity1 is as followed

public boolean onNavigationItemSelected(MenuItem Item)
{
    int id = item.getItemId();

    if(id == R.id.activity2)
    {
        Intent goPage2 = new Intent(activity1.this, activity2.class);
        startActivity(goPage2);
    }
}

there is no code in activity 2.

May I know what do I do to remove the highlight?



1> 小智..:

我发现如果不需要使用突出显示功能,只需在onNavigationItemSelected的末尾返回false即可。

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

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

    }

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



2> W4R10CK..:

要取消选中项目单击,必须传递false选中的项目:

public boolean onNavigationItemSelected(MenuItem Item) //will consider to keep this in lower case - item
{
int id = item.getItemId();

 if(id == R.id.activity2)
 {
    Intent goPage2 = new Intent(activity1.this, activity2.class);
    startActivity(goPage2);
    Item.setChecked(false);  //pass false to uncheck
 }
}

推荐阅读
coco2冰冰
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有