Android Navigation View transparency

為{幸葍}努か 提交于 2019-12-11 03:01:34

问题


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.


回答1:


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




回答2:


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:

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




回答3:


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

android:background="@android:color/transparent"



回答4:


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();


来源:https://stackoverflow.com/questions/41674469/android-navigation-view-transparency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!