我使用的是与搜索栏操作栏过了,我需要使用的动作条ICO像后退按钮:
不过,我使用的是抽屉式导航太...我怎么能开除/隐藏/禁用的抽屉式导航菜单,使用后退按钮?
我的动作条code:
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
MenuInflater充气= getMenuInflater();
inflater.inflate(R.menu.main,菜单);
this.getSupportActionBar()setDisplayShowCustomEnabled(真)。
this.getSupportActionBar()setDisplayShowTitleEnabled(假)。
this.getSupportActionBar()setDisplayHomeAsUpEnabled(真)。
this.getSupportActionBar()setHomeButtonEnabled(真)。
LayoutInflater充气=(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
视图V;
如果(!搜索查看){
V = inflator.inflate(R.layout.action_textview,NULL);
((TextView中)v.findViewById(R.id.titleText))的setText(actionTitle)。
menu.getItem(0).setVisible(真正的);
menu.getItem(2).setVisible(真正的);
MAINMENU =菜单;
}其他{
V = inflator.inflate(R.layout.action_searchview,NULL);
actionSearch =(EditText上)v.findViewById(R.id.searchText);
actionSearch.setOnEditorActionListener(新OnEditorActionListener(){
@覆盖
公共布尔onEditorAction(TextView的观点,诠释actionId,KeyEvent的事件){
INT结果= actionId和放大器; EditorInfo.IME_MASK_ACTION;
开关(结果){
案例EditorInfo.IME_ACTION_DONE:
案例EditorInfo.IME_ACTION_NEXT:
案例EditorInfo.IME_ACTION_GO:
情况下0:
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(actionSearch.getWindowToken(), 0);
字符串临时= actionSearch.getText()的toString()。
searchFor(临时);
打破;
}
返回true;
}
});
actionSearch.requestFocus();
menu.getItem(0).setVisible(假);
menu.getItem(2).setVisible(假);
}
this.getSupportActionBar()setCustomView(v)中。;
返回super.onCreateOptionsMenu(菜单);
}
code的帮助:
在我的标题了,只有一个TextView自定义视图,可自定义字体颜色和大小; (action_textview) 在我的搜索栏使用只用的EditText自定义视图; (action_searchview) 解决方案在 ActionBarDrawerToggle
则可以使用方法 setDrawerIndicatorEnabled(布尔启用)
。或者,您可以设置动作条
显示选项。具体的标志 DISPLAY_HOME_AS_UP
。 链接到文档
然后处理click事件,像往常一样。
I'm using the action bar with search bar too, and I need to use the ActionBar ico like a Back button:
But I'm using the navigation drawer too... How can I dismiss/hide/disable the Navigation Drawer menu to use the back button?
My ActionBar code:
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
this.getSupportActionBar().setDisplayShowCustomEnabled(true);
this.getSupportActionBar().setDisplayShowTitleEnabled(false);
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.getSupportActionBar().setHomeButtonEnabled(true);
LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v;
if(!searchView){
v = inflator.inflate(R.layout.action_textview, null);
((TextView) v.findViewById(R.id.titleText)).setText(actionTitle);
menu.getItem(0).setVisible(true);
menu.getItem(2).setVisible(true);
mainMenu = menu;
}else{
v = inflator.inflate(R.layout.action_searchview, null);
actionSearch = (EditText) v.findViewById(R.id.searchText);
actionSearch.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
int result = actionId & EditorInfo.IME_MASK_ACTION;
switch(result) {
case EditorInfo.IME_ACTION_DONE:
case EditorInfo.IME_ACTION_NEXT:
case EditorInfo.IME_ACTION_GO:
case 0:
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(actionSearch.getWindowToken(), 0);
String temp = actionSearch.getText().toString();
searchFor(temp);
break;
}
return true;
}
});
actionSearch.requestFocus();
menu.getItem(0).setVisible(false);
menu.getItem(2).setVisible(false);
}
this.getSupportActionBar().setCustomView(v);
return super.onCreateOptionsMenu(menu);
}
Code help:
My Title its a custom view with only a TextView, to customize the font color and size; (action_textview) My SearchBar use a custom view with only a EditText; (action_searchview)解决方案
From ActionBarDrawerToggle
you can use the method setDrawerIndicatorEnabled(Boolean enable)
. Alternatively, you can set the ActionBar
Display options. Specifically the flag DISPLAY_HOME_AS_UP
. Link to docs
Then handle the click event as usual.