Unable to make DrawerLayout background to transparent in Samsung s8+
Asked Answered
P

2

6

I am using DrawerLayout in my application. I am using NavigationView for the contents of the navigation drawer and setting its background to transparent using below code snip.

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start|center"
    android:background="@android:color/transparent">

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

In Samsung s8+ when I open the drawer it shows a vertical bar at the end. While debugging when I removed transparency from NavigationView what I come to know that Samsung s8+ contain a grey color bar in addition with a background. When I deploy the same code on Red mi 3s it's working fine it just has a background.

Samsung s8+ drawer bg enter image description here

Redmi 3s drawer bg enter image description here

Samsung s8+ drawer bg transparent enter image description here

Redmi 3s drawer bg transparent enter image description here

Please help me to remove this vertical bar.

Pogue answered 6/8, 2018 at 11:15 Comment(9)
Could you also try it out on an emulator to understand if Samsung S8+ is behaving differently by adding the grey bar or RedMi behaving differently by removing the bar. Other than that, try setting elevation of the view to 0dp.Zounds
@Zounds I didn't check on emulator no matter there its working or not. I set elevation to 0dp but it is not working.Pogue
@Zounds When I set elevation to 0dp that grey border come to left side instead of right side but once I rotate the device again it goes to right and if rotate again it comes to left.Pogue
Okay. One more idea, I suppose you use the DrawerLayout class. It also has its own shadow that it draws. You can maybe make use of DrawerLayout.setDrawerShadow(null, Gravity.xyz) and also setDrawerElevation(0)Zounds
@Zounds Yes, I am using DrawerLayout and I tried setDrawerShadow() and setDrawerElevation() but that also not working.Pogue
One more thing, try DrawerLayout.setScrimColor(Color.TRANSPARENT);Zounds
Sorry, @Zounds DrawerLayout.setScrimColor(Color.TRANSPARENT); also doesn't work :(Pogue
@AmitYadav try this #41674969Nebulize
@WaleedAsim I tried #41674969 but that also not worked.Pogue
V
0

I am unable to run the code right now. However I believe this will work.

navigationView.getBackground().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SOURCE);
Vellicate answered 18/8, 2018 at 14:32 Comment(2)
.@Anees navigationView.getBackground() return Drawable and that is not having setBackgroundColor() method. I mean to say that above statement give compilation issue.Pogue
.@Anees, I tried navigationView.getBackground().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC); but the code snip is not working.Pogue
R
-1

setDrawerShadow added in version 22.1.0 void setDrawerShadow (Drawable shadowDrawable, int gravity) 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 START. Alternatively, for API 23 and above, the drawable can auto-mirrored such that the drawable will be mirrored in RTL layout.

https://developer.android.com/reference/android/support/v4/widget/DrawerLayout#setDrawerShadow(int,%20int)

Create a color drawable or rectangle shape with transparent color R.drawable.trans then use it like this:

navigationDrawer.setDrawerShadow(R.drawable.trans, GravityCompat.END);
Radmen answered 11/9, 2018 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.