[英]Android ActionBar custom view and NavigationDrawer
I just ran into some problem with my project main activity. 我的项目主要活动遇到了一些问题。 I have a SherlockFragmentActivity with a NavigationDrawer and a SearchView on the ActionBar with a custom view. 我有一个带有NavigationDrawer的SherlockFragmentActivity和一个带有自定义视图的ActionBar上的SearchView。 The problem is when I type a query on my SearchView, I can do my search and all works fine, but when I close the SearchView, my ActionBar custom view and NavigationDrawer toggle disappear from the ActionBar. 问题是,当我在SearchView上键入查询时,我可以进行搜索并且一切正常,但是当我关闭SearchView时,ActionBar自定义视图和NavigationDrawer切换开关从ActionBar中消失了。
Here is the graphical problem 这是图形问题
Here is my NavigationDrawer 这是我的NavigationDrawer
private void initialiseDrawer(){
this.drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
this.drawerList = (ListView)findViewById(R.id.navigation_drawer);
this.drawerAdapter = new NavigationDrawerAdapter(MainActivity.this);
this.drawerList.setAdapter(drawerAdapter);
this.drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
handleDrawerSelectedPosition(position);
}
});
//getSupportActionBar().setHomeButtonEnabled(true);
this.drawerToggle = new ActionBarDrawerToggle(this, this.drawerLayout, R.drawable.drawer,
R.string.navigation_drawer_open, R.string.navigation_drawer_close){
public void onDrawerOpened(View view){
super.onDrawerOpened(view);
hideMenu();
}
public void onDrawerClosed(View view){
super.onDrawerClosed(view);
showMenu();
}
};
this.drawerLayout.setDrawerListener(drawerToggle);
this.drawerToggle.syncState();
}
And this is how I set my ActionBar 这就是我设置ActionBar的方式
private void showCustomActionBarView(){
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setCustomView(R.layout.action_bar_layout);
}
What can I do to show my custom View and DrawerToggle after the SearchView has been dettached? 拆下SearchView后,如何显示我的自定义View和DrawerToggle?
好吧,我在这里找到了自己的答案,我使用的是SherlockActionBar和支持库4.0,我刚刚删除了sherlock库,并将支持库升级到v7.21.03,实现了工具栏,所有问题都解决了,希望对我以外的人有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.