所以我正在看谷歌的api演示动作栏,他们有这个
// 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);
但是当我试图添加最后一行代码getwindow().requestFeature(Window.FEATURE_ACTION_BAR);我的应用程序刚启动就死了.那真的是什么呢?
解决方法:
秘密是呼叫的顺序.必须在填充任何内容之前调用请求功能.我按此顺序执行并且工作正常:
getwindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.your_activity_layout);