This question extends this thread How to hide ActionBar and NavigationBar after a certain delay time?
This works for my application. But it only runs once. How can I make it to keep executing until a button is pressed (back button)
Btw this is a photoViewer app (part of) like Gmail app on android when you view a photo.
Update1: I actually have a touchListener to show() and hide() the actionBar again. So what I want is when I'm in imageView layout, the actionBar will disappear in 3000ms, then I tap to show(), then after 3000ms it should disappear again. Again, just like Gmail android app when you load a picture from email
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); // overlay mode
setContentView(R.layout.fullscreen_image);
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbar_top);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// time delay to hide actionBar
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
// DO DELAYED STUFF
getActionBar().hide();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}, 3000); // e.g. 3000 milliseconds
....
Button back = (Button)findViewById(R.id.btnBack);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});