Nazila
Nazila

Reputation: 1453

How to remove toolbar shadow in Android?

Hi I am developing an app and I want to remove toolbar shadow, I tried adding app:elevation="0dp" to AppBarLayout but after adding this the menu button for opening navigationView does not work,Any idea?

public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
private SlidingMenuLayout slidingMenuLayout;
private NavigationView navigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    slidingMenuLayout = (SlidingMenuLayout) this.getLayoutInflater().inflate(
            R.layout.activity_main, null);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(slidingMenuLayout);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    toolbar.setLogo(R.drawable.notifications);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.dashboard_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.open_drawer:
            toggleMenu();
        default:
            return super.onOptionsItemSelected(item);
    }
}

private void toggleMenu() {
    slidingMenuLayout.toggleMenu();
 } }

activity_main.xml:

<net.aparteman.apartemanapp.viewHolder.SlidingMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:background="@color/dark_purple"
    android:layoutDirection="rtl"
    android:textDirection="rtl"
    app:elevation="0dp"
    app:headerLayout="@layout/dashboard_nav_header"
    app:itemTextColor="@color/white"
    app:menu="@menu/dashboard_drawer_view"
    app:theme="@style/ApartemanStyle" />

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    tools:context=".activity.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:popupTheme="@style/AppTheme" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/dashboard_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>

Upvotes: 0

Views: 284

Answers (1)

rupps
rupps

Reputation: 9887

As elevation also affects the View's z-index, I guess what's happening is that your FrameLayout is above the Toolbar, eating the touch events.

Try to either put the FrameLayout before the AppBarLayout in the XML, or define your FrameLayout with a top margin to leave room to the Toolbar.

Upvotes: 1

Related Questions