Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在使用appcompat21时隐藏导航抽屉指示器_Android_Android Actionbar_Navigation Drawer_Android Appcompat - Fatal编程技术网

Android 如何在使用appcompat21时隐藏导航抽屉指示器

Android 如何在使用appcompat21时隐藏导航抽屉指示器,android,android-actionbar,navigation-drawer,android-appcompat,Android,Android Actionbar,Navigation Drawer,Android Appcompat,我使用工具栏小部件作为Cris Banes指南下的操作栏。 在我的用例中,我需要在活动中隐藏导航抽屉,同时滑动到ViewPager中包含的另一个片段。 以前,我在使用ActionBar小部件隐藏导航抽屉时使用了以下属性。这似乎工作正常。 getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false) 虽然现在在使用时更改为AppCompat21 getSupportAction

我使用工具栏小部件作为Cris Banes指南下的操作栏。 在我的用例中,我需要在活动中隐藏导航抽屉,同时滑动到ViewPager中包含的另一个片段。 以前,我在使用ActionBar小部件隐藏导航抽屉时使用了以下属性。这似乎工作正常。
getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setHomeButtonEnabled(false)

虽然现在在使用时更改为AppCompat21

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
这似乎并没有隐藏actionBar中的导航抽屉。 在这方面,我是否遗漏了什么?感谢您的帮助

toolbar.setNavigationIcon(null);

它将隐藏导航图标,以供参考。您可以选中此复选框。只有在使用以下选项时,您的代码才能工作:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

您也可以尝试:

toolbar.setNavigationIcon(null);

如果您正在
抽屉布局中使用
工具栏
-->
AppBarLayout

然后上课

ActionBarDrawerToggle-->setDrawerIndicatorEnabled(false) 
功能将使导航抽屉图标不可见。如

public class MainActivity extends AppCompatActivity
                implements NavigationView.OnNavigationItemSelectedListener
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
//the below line of code will allow you to hide the nav drawer icon 
        toggle.setDrawerIndicatorEnabled(false);    
        toggle.syncState();

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

谢谢,它似乎隐藏了导航图标,但我没有为setIcon使用自定义图标。那么,我该如何取回导航抽屉指示器呢?谢谢,我用toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha))实现了它;谢谢你,setNavi。。似乎隐藏了它,但显示回我使用。toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha))@我讨厌求助于像那样的黑客解决方案,但有时也没办法。请注意,可能会来找我的网络旅行者。。。请务必使用getSupportActionBar(),而不是getActionBar()。当我尝试此操作时,会显示一个返回箭头图标,而不是汉堡包(3行)图标:-(…哎呀。发生这种情况是因为我仍然有
actionBar.setDisplayHomeAsUpEnabled(true);actionBar.setHomeButtonEnabled(true);
。删除它们,它现在工作得很好。10分!:-)
public class MainActivity extends AppCompatActivity
                implements NavigationView.OnNavigationItemSelectedListener
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
//the below line of code will allow you to hide the nav drawer icon 
        toggle.setDrawerIndicatorEnabled(false);    
        toggle.syncState();

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