Android 导航视图透明度
Android Navigation View transparency
各位。是否可以使 Navigation View
透明?
我有自定义布局并尝试为此布局设置 50% 透明背景,Navigation View
或 Drawer Layout
。
android:background="#80000000"
但没有给出预期的结果。
有人试过这样做吗?我将不胜感激帮助。
你可以试试:
navigationView.getBackground().setAlpha(122);
在这里您可以设置 0(完全透明)到 255(完全不透明)之间的不透明度。
您还可以使用 XML 值 alpha
取双值。
范围是0f到1f(含),0f为透明,1f为不透明:
android:alpha="0.0"
看不见
android:alpha="0.5"
see-through
android:alpha="1.0"
完全可见
要使导航透明,请尝试以下代码
final Window window = getWindow();
ObjectAnimator animator = ObjectAnimator.ofInt(window,
"navigationBarColor", window.getNavigationBarColor(), Color.TRANSPARENT);
animator.setEvaluator(new ArgbEvaluator());
animator.setDuration(0);
animator.start();
如果你想要有颜色的透明度试试这个..
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);
输出:
如果您需要更多关于可以应用哪些颜色代码的细节,请查看我的回答here
或者如果您只想设置 alpha 使用 navigationView.getBackground().setAlpha(intNumberTill256);
p.s 导航标题深色是由于我在 XML
中给出的背景颜色
为了使导航视图完全透明,这对我有用。
android:background="@android:color/transparent"
各位。是否可以使 Navigation View
透明?
我有自定义布局并尝试为此布局设置 50% 透明背景,Navigation View
或 Drawer Layout
。
android:background="#80000000"
但没有给出预期的结果。
有人试过这样做吗?我将不胜感激帮助。
你可以试试:
navigationView.getBackground().setAlpha(122);
在这里您可以设置 0(完全透明)到 255(完全不透明)之间的不透明度。
您还可以使用 XML 值 alpha
取双值。
范围是0f到1f(含),0f为透明,1f为不透明:
android:alpha="0.0"
看不见
android:alpha="0.5"
see-through
android:alpha="1.0"
完全可见
要使导航透明,请尝试以下代码
final Window window = getWindow();
ObjectAnimator animator = ObjectAnimator.ofInt(window,
"navigationBarColor", window.getNavigationBarColor(), Color.TRANSPARENT);
animator.setEvaluator(new ArgbEvaluator());
animator.setDuration(0);
animator.start();
如果你想要有颜色的透明度试试这个..
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);
输出:
如果您需要更多关于可以应用哪些颜色代码的细节,请查看我的回答here
或者如果您只想设置 alpha 使用 navigationView.getBackground().setAlpha(intNumberTill256);
p.s 导航标题深色是由于我在 XML
中给出的背景颜色为了使导航视图完全透明,这对我有用。
android:background="@android:color/transparent"