I have added Sherlock action bar to an activity by using the following line in manifest:
android:theme="@style/Theme.Sherlock.Light"
I want to save on screen space and hide the action bar by default and show it only when user taps on the screen. I have seen it in Aldiko app but don't know how to implement it.
Any help is welcomed.
First give the id to your wrapping node of activity layout (main_layout.xml):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/containerMain"
Second implement this in your code for activity:
boolean isActionBarShow=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
a=getSupportActionBar();
RelativeLayout rl= (RelativeLayout)findViewById(R.id.containerMain);
rl.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_DOWN)
if (isActionBarShow)
{
a.hide();
isActionBarShow=false;
}
else
{
a.show();
isActionBarShow=true;
}
return false;
}
});
To hide use below code on your activity onCreate()
method,
getSupportActionBar().hide();
To show use below code on tap event,
getSupportActionBar().show();
Follow ActionBarSherlock Usage for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With