How to make the support Toolbar background transparent?

后端 未结 2 1723
南笙
南笙 2020-12-19 03:25

Is there a way to make the new Android support Toolbar:

android.support.v7.widget.Toolbar

Have a transparent background?

I tried se

相关标签:
2条回答
  • 2020-12-19 03:52

    To answer Nicholas Pesa's question and maybe some others in the future you could set the alpha with a float by using a ratio, something like.

    mToolbar.getBackground().setAlpha((int)(myFloatValue) * 255);
    
    0 讨论(0)
  • 2020-12-19 04:04

    You can either set the background to android's default transparent color, which works just fine. Add this to the layout you want a transparent Toolbar:

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

    If you want to change the alpha programmatically, you can do it by modifying the alpha on the Toolbar background itself. Just get an instance of the Drawable and set the alpha there:

    mToolbar = findViewById(R.id.my_toolbar);
    mToolbar.getBackground().setAlpha(0);
    
    0 讨论(0)
提交回复
热议问题