Toolbar
Toolbar is act like actionbar and have more extra features.It can be supported below v 21 also if you use AppCompat V7 lib
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
}
public void hideToolbar(View v){
// startActivity(new Intent(this,ChildActivity.class));
ActionBar actionBar = getSupportActionBar();
if(actionBar.isShowing()){
actionBar.hide();
}else {
actionBar.show();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<Button
android:layout_below="@+id/my_toolbar"
android:onClick="hideToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click me"/>
</RelativeLayout>