如何在使用appcompat21时隐藏导航抽屉指示器
我使用工具栏小部件作为Cris Barnes指南后面的ActionBar。 在我的用例中,我需要隐藏活动中的导航抽屉,同时滑动到ViewPager中包含的另一个片段。 之前,我在使用ActionBar Widget来隐藏导航Drawer时使用了以下属性。这似乎工作正常。 getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false);
如何在使用appcompat21时隐藏导航抽屉指示器
虽然现在使用
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
时,这似乎并没有隐藏ActionBar中的抽屉式导航栏更改为AppCompat21。 我在这方面缺少的东西,任何帮助表示赞赏。
当你用你的代码应该只工作:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
和
getSupportActionBar().setHomeButtonEnabled(false);
你也可以试试:
toolbar.setNavigationIcon(null);
谢谢toolbar.setNavi ..似乎隐藏它,但为了显示它回来ihad使用。 toolbar.setNavigationIcon(getResources()getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); – harshitpthk 2015-03-02 07:16:30
如果您正在使用Toolbar
的DrawerLayout
内 - >AppBarLayout
那么类
ActionBarDrawerToggle-->setDrawerIndicatorEnabled(false)
功能将使导航抽屉图标invisible.like
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);
}
当我尝试这个时,我得到一个后退箭头图标而不是汉堡(3行)图标。 :-( – 2017-09-23 00:11:03
... oops。发生这种情况是因为我还有'actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true);'。删除它们,现在它工作得很好,10分!:-) – 2017-09-23 00:14:53
谢谢,这似乎隐藏导航图标,但我没有使用setIcon的自定义图标。那么,我将如何获取导航抽屉指标。 – harshitpthk 2015-03-02 07:06:18
感谢它使用toolbar.setNavigationIcon(getResources()。getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); – harshitpthk 2015-03-02 07:15:31