问题描述
根据谷歌的文档, getActionBar()。setDisplayHomeAsUpEnabled(真)
是需要显示向上按钮。我创建使用向导在Eclipse中裸骨活性和指定的父活动。我找不到任何 getActionBar()。setDisplayHomeAsUpEnabled(真)
在自动生成的code,但向上按钮时,这个活动开始present和它按预期工作。任何人都可以揭示出这个一些轻?
公共类FooActivity扩展ActionBarActivity {
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_foo);
//更多code ...
}
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//更多code ...
}
@覆盖
公共布尔onOptionsItemSelected(菜单项项){
//处理动作栏项目点击这里。将操作栏
//自动在主/向上按钮操作的点击,只要
//你在AndroidManifest.xml中指定一个父活动。
INT的id = item.getItemId();
如果(ID == R.id.action_settings){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
/ **
*包含一个简单的视图的占位符片段。
* /
公共静态类PlaceholderFragment扩展片段{
公共PlaceholderFragment(){
}
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
捆绑savedInstanceState){
//更多code ...
返回rootView;
}
}
}
在指定 parentActivityName
在 AndroidManifest
, Acitivty
will检查是否存在,并自动启用向上的启示,如果它是present。
According to Google's document, getActionBar().setDisplayHomeAsUpEnabled(true)
is needed to show the up button. I created a bare-bone activity using the wizard in Eclipse and specified its parent activity. I could not find any getActionBar().setDisplayHomeAsUpEnabled(true)
in the automatically generated code, but the up button is present when this activity is started and it works as expected. Could anyone shed some light on this?
public class FooActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foo);
//more code...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//more code...
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//more code...
return rootView;
}
}
}
When you specify a parentActivityName
in your AndroidManifest
, Acitivty
will check for that and automatically enable the "up" affordance if it's present.
这篇关于为什么不setDisplayHomeAsUpEnabled向上按钮present()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!