Transparent actionBar and statusBar in candies on Android

I am trying to create this interface:

enter image description here

And here is my actual result:

enter image description here

  • The status bar is well transparent, and we see our image as a background: OK
  • Action bar is not transparent: NOK

Here is the code for my theme that I use for this action:

<?xml version="1.0" encoding="utf-8"?> <resources> <!-- inherit from the material theme --> <style name="MaterialAppDetailTheme" parent="android:Theme.Material.Light"> <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowActionBarOverlay">true</item> <!-- enable window content transitions --> <item name="android:windowContentTransitions">true</item> <!-- specify shared element transitions --> <item name="android:windowSharedElementEnterTransition"> @transition/change_image_transform</item> <item name="android:windowSharedElementExitTransition"> @transition/change_image_transform</item> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentStatus">true</item> </style> </resources> 
+5
source share
3 answers

You can change the color of the panel as follows:

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

You can also change its background to XML:

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

Or if you use an ActionBar:

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

Use getActionBar() if you are not using ActionBarActivity

Result:

enter image description here

+4
source

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> 
+1
source

For an API that is> = 21, add these lines of code to the topic

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

Do not forget to add

android:fitsSystemWindows="true"

0
source

Source: https://habr.com/ru/post/1212634/


All Articles