4

everyone. Is it possible to make Navigation View transparent? I have custom layout and try to set 50% transparent background for this layout, Navigation View or Drawer Layout.

android:background="#80000000"

but it doesn't give expected result.

Anybody tried to do this? I would appreciate help.

Peter Parker
  • 560
  • 1
  • 5
  • 17

4 Answers4

8

you can try:

navigationView.getBackground().setAlpha(122);

Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque).

you can also use XML value alpha that takes double values.

The range is from 0f to 1f (inclusive), 0f being transparent and 1f being opaque:

android:alpha="0.0" invisible

android:alpha="0.5" see-through

android:alpha="1.0" full visible

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
4

If you want transparency with a color try this..

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
------
// you can even change only one from above to and keep the other one normally 
       navigationView.getBackground().setColorFilter(0x80000000, PorterDuff.Mode.MULTIPLY);
       headerView.getBackground().setColorFilter(0x80000000, PorterDuff.Mode.MULTIPLY);

Output:

enter image description here enter image description here

If you need more deatals about which colour codes you can apply check my answer here


Or if you only want to set alpha use navigationView.getBackground().setAlpha(intNumberTill256);

p.s Nav headder dark colour is due to it's background colour that i have given in its XML

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88
  • Great, +1 ..! Also as a top user in *Android* tag, can you please answer to this short question? Should I have one `public static void main(){}` method per each either **class** or **file** or **project** ? – stack Jan 18 '17 at 10:51
  • 2
    @stack well i would say it like this,First why you want a method like that? Then if you think that should be the way to start fiest method of a class in android..No..In **core Java** programs we need a `main()` method, because while executing the byte code the JVM will search for the `main()` method in the class and start executing there..In the case of **Android**, there is a manifest included in each package. The launchpoint is specified in this manifest.It start the execution of the application from specified class `onCreate()` method, so there is no need of a `main()` method – Charuක Jan 18 '17 at 11:39
  • 2
    @stack read about android life cycle // If you have any doubt post a comment an ask http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for – Charuක Jan 18 '17 at 11:42
3

To make navigation view completely transparent, this worked for me.

android:background="@android:color/transparent"
crgarridos
  • 8,758
  • 3
  • 49
  • 61
Kaveri
  • 1,060
  • 2
  • 12
  • 21
1

To make transparent for navigation , please try below code

final Window window = getWindow();
    ObjectAnimator animator = ObjectAnimator.ofInt(window,
            "navigationBarColor", window.getNavigationBarColor(), Color.TRANSPARENT);
    animator.setEvaluator(new ArgbEvaluator());
    animator.setDuration(0);
    animator.start();
Navas pk
  • 331
  • 3
  • 17