微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 带动作栏的requestFeature

所以我正在看谷歌的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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐