所以我正在看谷歌的动作栏的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);
我的应用程序在启动时就已经死了。那真的是什么呢?
答案 0 :(得分:1)
秘密是呼叫的顺序。必须在填写任何内容之前调用请求功能。我按此顺序执行并且工作正常:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.your_activity_layout);
答案 1 :(得分:0)
我知道这已经很晚了,你试过吗
requestWindowFeature(Window.FEATURE_ACTION_BAR)