所以我正在查看 google 的操作栏 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)