问题描述
调用 getActionBar
返回空
。这已被经常报道,所以我做了一定要包括他人已经使用的解决方案:我的的minSdkVersion = 11
,我有一个标题栏,和我打电话 getActionBar
在的setContentView
。另外,我的活动是不是一个子活动。
Calling getActionBar
returns null
. This has been frequently reported so I've made sure to include the solutions others have used: My minSdkVersion=11
, I do have a titlebar, and I'm calling getActionBar
after setContentView
. Also, my activity is not a child activity.
setContentView(R.layout.main);
// experiment with the ActionBar
ActionBar actionBar = getActionBar();
actionBar.hide();
设备是三星Galaxy Tab 10.1运行Android 3.2
Device is a Samsung Galaxy Tab 10.1 running Android 3.2
先谢谢您的任何意见或建议!
Thanks in advance for any ideas or suggestions!
推荐答案
看来你需要请求或者通过一个主题或通过以下code有一个动作条(!=标题栏)。
It seems you need to request having an Actionbar (!= titlebar) either via a Theme or via below code.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The Action Bar is a window feature. The feature must be requested
// before setting a content view. Normally this is set automatically
// by your Activity's theme in your manifest. The provided system
// theme Theme.WithActionBar enables this for you. Use it as you would
// use Theme.NoTitleBar. You can add an Action Bar to your own themes
// by adding the element <item name="android:windowActionBar">true</item>
// to your style definition.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.main);
// experiment with the ActionBar
ActionBar actionBar = getActionBar();
actionBar.hide();
}
$ C $从[here]
这篇关于getActionBar返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!