Using API21+ Toolbar
:
// Toolbar
Toolbar toolbar = new Toolbar(this);
toolbar.showOverflowMenu();
Would like to remove its shadow
Put this code in Fragment
in which you want to hide the ToolBar
.
@Override
public void onResume() {
super.onResume();
((AppCompatActivity)getActivity()).getSupportActionBar().setElevation(0);
}
If you are using AppBarLayout in toolbar, you can use:
app:elevation="0dp"
instead of
android:elevation
in AppBarLayout
Use app:elevation="0dp"
instead of android:elevation
on your toolbar.
If it is not work, put your toolbar inside of a AppBarLayout
and set app:elevation="0dp"
:
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
...
</android.support.design.widget.AppBarLayout>
set "#00000000" to the backgroundColor of toolbar ,
remember that:
if you use CoordinatorLayout and AppBarLayout ,you should remove the
app:layout_behavior="@string/appbar_scrolling_view_behavior"
of your contentView , I have made this elementary mistake.