First specify the identifier of your packaging node 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"
The second is implemented 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; } });
source share