[Android删除导航抽屉上的阴影

问题描述 投票:8回答:3

See here what i mean

[嗨,我使用的是普通的导航抽屉v4,我问打开导航抽屉时如何删除背景阴影。

这是我的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);

这是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>
android android-activity navigation shadow drawer
3个回答
14
投票

我找到了解决方法:D

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

在MainActivity.java中添加它


1
投票

您可以使用setDrawerShadow方法指向透明的可绘制对象:

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

0
投票

这在androidX中对我有效

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

/*Remove navigation drawer shadow/fadding*/
drawerLayout.setDrawerElevation(0);
© www.soinside.com 2019 - 2024. All rights reserved.