Android- hide actionbar during startup and then show it again?

泄露秘密 提交于 2019-12-22 03:50:56

问题


My android app has tab navigation using an action bar. It works well, but it bothers me that during the first boot of the app, a small default action bar briefly shows up before being replaced by the real, tab-navigation action bar. My onCreate starts like this:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    setContentView(R.layout.activity_main);

    //Set up the actionbar
    final ActionBar actionBar = getActionBar();
.
.
.

What do I have to do so that the real actionbar will be initialized without a small default one briefly showing before it does on startup?

Thanks


回答1:


Hide during startup

 getSupportActionBar().hide();

After you can show it again with ...

 getSupportActionBar().show();

It should be the same with native ActionBar of Android.

you should use this line in manifest and don't use getActionBar()

<item name="android:windowActionBar">false</item>

and once it's finished in the main Activity use below or nothing

<item name="android:windowActionBar">true</item>



回答2:


put this for your activity manifest definition:

 <activity
            android:name=".MyActivity"
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            >

then inside your oncreate do this to show the actual theme you want used:

setTheme(R.style.AppTheme); 



回答3:


if you're using action bar sherlock and you want to toggle this from a FragmentActivity, then you call

getSherlockActivity().getSupportActionBar().hide();


来源:https://stackoverflow.com/questions/12469721/android-hide-actionbar-during-startup-and-then-show-it-again

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