Transparent action bar with AppCompat-v7 21

Is there a way to make ActionBar transparent in Material Design via Appcompat-v7 21? Unfortunately this does not work.

<item name="colorPrimary">@android:color/transparent</item> 

Also not old:

  <style name="Widget.Styled.ActionBar" parent="Widget.AppCompat.Light.ActionBar"> <item name="android:background">@android:color/transparent</item> </style> 
+15
android material-design appcompat
Oct 19 '14 at 16:06
source share
4 answers
 <!-- Application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="android:actionBarStyle">@style/MyActionBar</item> <!-- Support library compatibility --> <item name="actionBarStyle">@style/MyActionBar</item> </style> <!-- ACTION BAR STYLES --> <style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar"> <item name="android:background">@drawable/actionbar_background</item> <item name="android:windowActionBarOverlay">true</item> <!-- Support library compatibility --> <item name="background">@drawable/actionbar_background</item> <item name="windowActionBarOverlay">true</item> </style> 
+25
Oct 19 '14 at 16:14
source share

Actually, it is quite easy and simple.

  • Just make sure you use RelativeLayout to place the Toolbar and body.
  • Put the Toolbar on the last.
  • Set a transparent color for the android:background Toolbar attribute

This is an example of working code:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="vertical"> <fragment android:id="@+id/fragment_editor" android:name="ichsan.myapp.HelloFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:layout="@layout/fragment_editor" /> <android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="#10000000" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </RelativeLayout> 

I hope he answers the question.

+23
Dec 30 '15 at 12:55
source share

Step:

1. enter the style below v21 \ styles.xml

 <style name="TransperantToolbar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item> </style> 

2. Your toolbar XML

 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:theme="@style/TransperantToolbar"/> 

Output

+1
Dec 09 '15 at 5:50
source share

None of the above helped (or at least not at all) using appcompat v7 23 and the Layout coordinator, which is most likely the culprit. If you go this route, you probably have the main kind of work that looks like

 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.farmdog.farmdog.MainActivity"> <android.support.v4.view.ViewPager android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_anchor="@+id/appbar" app:layout_anchorGravity="top" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> <!--android:theme="@style/AppTheme.AppBarOverlay">--> ... 

Pay attention to the two string binding lines above - they did it for me.

0
Jan 11 '16 at 2:33
source share



All Articles