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);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...