Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

android.support.v7.widget.Toolbar

Have a transparent background?

I tried setting the colorPrimary to an ARGB (#00ffffff) but it just gives me a solid gray bar. And Toolbar only allows me to set a background drawable. Is it kosher to set the background drawable to a transparent PNG, or is there a better way to do this?

Ideally I'd be able to do it in code / animate it so certain activities have a transparent bar and some activities don't.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
385 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...