Transparent actionBar and statusBar in Android lollipop

戏子无情 提交于 2019-11-29 13:55:44

You can change your toolbar color to transparent like this:

mToolbar.setBackgroundColor(getResources().getColor(android.R.color.transparent));

You can change it's background on the XML too:

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

Or if you're using ActionBar:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

Use getActionBar() if you're not using ActionBarActivity

Result:

Use this style:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:textColorPrimary">@color/my_text_color</item>
    <item name="colorPrimary">@android:color/transparent</item>
    <item name="windowActionBarOverlay">true</item>
</style>

For API that >= 21, add to theme these lines of code

<item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@android:color/transparent</item>

Don't forget to add

android:fitsSystemWindows="true"

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