Android Remove Shadow On Navigation Drawer

核能气质少年 提交于 2019-12-01 16:21:02

问题


See here what i mean

Hi, I'm using stock Navigation drawer v4 and i ask how can delete that background shadow when navigation drawer is open.

this is my code of NavigationDrawerFragment.java

public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.trasparent, GravityCompat.START);
    // set up the drawer's list view with items and click listener

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

And this is MainActivity.xml

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Main layout -->
    <FrameLayout
        android:id="@+id/main_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <ImageView
        android:id="@+id/ImageView3_Left"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:background="#FFFFFFFF"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"/>

</android.support.v4.widget.DrawerLayout>

回答1:


I find the solution :D

mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));

Adding this in MainActivity.java




回答2:


You can use the setDrawerShadow method to point to a transparent drawable:

navigationDrawer.setDrawerShadow(R.drawable.someDrawable, GravityCompat.START);



回答3:


This is works for me in androidX

/*Navigation drawer with transparent background*/
drawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));

/*Remove navigation drawer shadow/fadding*/
drawerLayout.setDrawerElevation(0);


来源:https://stackoverflow.com/questions/31568530/android-remove-shadow-on-navigation-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!