android - AppCompat style background propagated to the Image within the ToolBar -
context
i'm using newest appcompat v7 lib (21.0.0) , have migrated app actionbar toolbar
problem
images in toolbar automatically receive same background toolbarcurrently searchbox custom view set on action bar (from previous implementation) plan switch if searchview , style accordingly i'm still interested in problem i'm facing right now.
when long pressing on menu item in toolbar toast appear hint text , text has same background toolbar.how can avoid this?
here toolbar layout , style & theme
layout v_toolbar.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/my_awesome_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:popuptheme="@style/themeoverlay.appcompat.light" app:theme="@style/myactionbarstyle"/>
values/styles.xml
<style name="myactionbarstyle" parent="@style/themeoverlay.appcompat.dark.actionbar"> <item name="android:background">@color/green</item> <item name="android:windowactionbaroverlay">true</item> <!-- back upwards library compatibility --> <item name="background">@color/green</item> <item name="windowactionbaroverlay">true</item> </style>
theme
<style name="mytheme" parent="appbasetheme"> <!-- here setting appcompat’s actionbarstyle --> <!-- <item name="actionbarstyle">@style/myactionbarstyle</item> --> <item name="windowactionbar">false</item> <!-- ...and here setting appcompat’s color theming attrs --> <item name="colorprimary">@color/green</item> <item name="colorprimarydark">@color/green_dark</item> </style>
workaround 1 problem 1
the workaround first problem set transparent background on imageview
android:background="@color/transparent"
this not solve toast issue.
solution both problems
i set background toolbar
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/my_awesome_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/green" app:popuptheme="@style/themeoverlay.appcompat.light" app:theme="@style/myactionbarstyle"/>
and i'm not setting background on theme anymore.
<style name="myactionbarstyle" parent="@style/themeoverlay.appcompat.dark.actionbar"> <item name="android:windowactionbaroverlay">true</item> <!-- back upwards library compatibility --> <item name="windowactionbaroverlay">true</item> </style>
as pointed chris banes, style created toolbar instead of declaring android:background.
this fixes problem seem have issue fact popuptheme isn't applied , shareactionmenuitem drop downwards not have white background black text. see question here: appcompat toolbar popuptheme not used in shareaction menuitem
maybe bug in appcompat library.
you should not using theme
that:
workaround 2, phone call it, kind of right way. if want extract values style, can so:
<android.support.v7.widget.toolbar android:id="@+id/my_awesome_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" style="@style/mydarktoolbar" />
style:
<style name="mydarktoolbarstyle" parent="widget.appcompat.toolbar"> <item name="android:background">@color/green</item> <item name="popuptheme">@style/themeoverlay.appcompat.light</item> <item name="theme">@style/themeoverlay.appcompat.dark.actionbar</item> </style>
android appcompat android-toolbar
No comments:
Post a Comment