问题
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