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

har*_*thk 11 android android-appcompat android-actionbar navigation-drawer

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

虽然现在使用时改为AppCompat21

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
Run Code Online (Sandbox Code Playgroud)

这似乎没有隐藏actionBar中的导航抽屉.我在这方面遗漏了一些任何帮助表示赞赏.

Rob*_*ood 18

toolbar.setNavigationIcon(null);
Run Code Online (Sandbox Code Playgroud)

它会隐藏导航图标,供参考,您可以查看此答案


Nav*_*Jha 10

如果你在Toolbar里面使用DrawerLayout - >AppBarLayout

然后上课

ActionBarDrawerToggle-->setDrawerIndicatorEnabled(false) 
Run Code Online (Sandbox Code Playgroud)

函数将导航抽屉图标不可见

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);
    }
Run Code Online (Sandbox Code Playgroud)


Sto*_*eev 7

只有在您使用以下代码时,您的代码才能工作:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Run Code Online (Sandbox Code Playgroud)

getSupportActionBar().setHomeButtonEnabled(false);
Run Code Online (Sandbox Code Playgroud)

你也可以试试:

toolbar.setNavigationIcon(null);
Run Code Online (Sandbox Code Playgroud)