requestFeature with action bar

放肆的年华 提交于 2019-12-10 15:14:44

问题


So I was looking at google's api demos for action bars and they have this

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

but when I tried to add the last line of code getWindow().requestFeature(Window.FEATURE_ACTION_BAR); My app just dies on start up. So what does it really do?


回答1:


The secret is the order of the callings.The requestfeature must be called before fill nothing. I do it in this order and works fine:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.your_activity_layout);



回答2:


I know this is very late, did you try

requestWindowFeature(Window.FEATURE_ACTION_BAR)


来源:https://stackoverflow.com/questions/8319664/requestfeature-with-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!