DrawerLayout常见问题

DrawerLayout常见问题_第1张图片
图片.png

1.取消DrawerLayout滑出时内容区(Content)域遮罩效果:

如图中Content区域的遮罩半透明效果

源码:

android\support\v4\widget\DrawerLayout.java:

/**
 * Set a color to use for the scrim that obscures primary content while a drawer is open.
 *
 * @param color Color to use in 0xAARRGGBB format.
 */
public void setScrimColor(@ColorInt int color) {
    mScrimColor = color;
    invalidate();
}

解决办法:

将遮罩层颜色设置为透明即可

mDrawerLayout.setScrimColor(Color.TRANSPARENT);

2.取消DrawerLayout滑出时菜单区(Menu)边缘阴影效果:

如图中Menu区域边缘阴影效果

源码:

android\support\v4\widget\DrawerLayout.java:

/**
 * Set a simple drawable used for the left or right shadow. The drawable provided must have a
 * nonzero intrinsic width. For API 21 and above, an elevation will be set on the drawer
 * instead of using the provided shadow drawable.
 *
 * 

Note that for better support for both left-to-right and right-to-left layout * directions, a drawable for RTL layout (in additional to the one in LTR layout) can be * defined with a resource qualifier "ldrtl" for API 17 and above with the gravity * {@link GravityCompat#START}. Alternatively, for API 23 and above, the drawable can * auto-mirrored such that the drawable will be mirrored in RTL layout.

* * @param resId Resource id of a shadow drawable to use at the edge of a drawer * @param gravity Which drawer the shadow should apply to */ public void setDrawerShadow(@DrawableRes int resId, @EdgeGravity int gravity) { setDrawerShadow(ContextCompat.getDrawable(getContext(), resId), gravity); }

解决办法:

自定义一个阴影效果

mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

你可能感兴趣的:(DrawerLayout常见问题)