Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ActionBar glitch on show and hide

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

            }
        });
    }
like image 700
Rob Avatar asked Dec 27 '12 18:12

Rob


1 Answers

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.

like image 98
AlikElzin-kilaka Avatar answered Oct 19 '22 20:10

AlikElzin-kilaka