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.

Gaurang Goda
  • 3,394
  • 4
  • 20
  • 29
Amit Yadav
  • 32,664
  • 6
  • 42
  • 57
  • 1
    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. – mtiidla Aug 14 '18 at 13:56
  • 1
    @mtiidla I didn't check on emulator no matter there its working or not. I set elevation to 0dp but it is not working. – Amit Yadav Aug 14 '18 at 15:09
  • 1
    @mtiidla 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. – Amit Yadav Aug 15 '18 at 05:56
  • 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) – mtiidla Aug 15 '18 at 07:31
  • 1
    @mtiidla Yes, I am using DrawerLayout and I tried setDrawerShadow() and setDrawerElevation() but that also not working. – Amit Yadav Aug 15 '18 at 10:47
  • One more thing, try DrawerLayout.setScrimColor(Color.TRANSPARENT); – mtiidla Aug 15 '18 at 14:56
  • Sorry, @mtiidla DrawerLayout.setScrimColor(Color.TRANSPARENT); also doesn't work :( – Amit Yadav Aug 16 '18 at 06:25
  • @AmitYadav try this https://stackoverflow.com/questions/41674469/android-navigation-view-transparency – Tara Aug 20 '18 at 07:14
  • @WaleedAsim I tried https://stackoverflow.com/questions/41674469/android-navigation-view-transparency but that also not worked. – Amit Yadav Aug 20 '18 at 08:07

2 Answers2

0

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

navigationView.getBackground().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SOURCE);
Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
  • .@Anees navigationView.getBackground() return Drawable and that is not having setBackgroundColor() method. I mean to say that above statement give compilation issue. – Amit Yadav Aug 18 '18 at 15:00
  • .@Anees, I tried navigationView.getBackground().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC); but the code snip is not working. – Amit Yadav Aug 23 '18 at 08:55
-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);
ygngy
  • 3,630
  • 2
  • 18
  • 29