Android: ActionBar glitch on show and hide

拜拜、爱过 提交于 2021-02-07 08:13:36

问题


I would like to show/hide the action bar upon a click.

It does show and hide but it is not smooth...the bottom part hides but a different background for a little while before disappearing.

I even tried it in a simple hello world app and the result is the same. Here's the code:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = (TextView) findViewById(R.id.shit);
        tv.setOnClickListener(new OnClickListener() {


            public void onClick(View v) {
                getActionBar().hide();

            }
        });
    }

回答1:


Use overlay mode instead of showing and hiding the actionbar.

From the actionbar documentation:

Beware that hiding and removing the action bar causes your activity to re-layout in order to account for the space consumed by the action bar. If your activity regularly hides and shows the action bar (such as in the Android Gallery app), you might want to use overlay mode. Overlay mode draws the action bar on top of your activity layout rather than in its own area of the screen. This way, your layout remains fixed when the action bar hides and re-appears. To enable overlay mode, create a theme for your activity and set android:windowActionBarOverlay to true. For more information, see the section about Styling the Action Bar.



来源:https://stackoverflow.com/questions/14059282/android-actionbar-glitch-on-show-and-hide

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