Reputation: 484
I've been trying to customize my Toolbar using the support library. while setting android:theme works perfectly on API21+ , lower APIs seem to completely ignore it.
here's my xml:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
makes the toolbar have White icons in API21+, the icons remain black on older devices.
update: I tested by adding another child (tabLayout) to my appBarLayout. the theme was correctly applied. however the support toolbar completely refuses to recognize the theme even if set directly.
Upvotes: 1
Views: 98
Reputation: 321
You have set the theme style in API version based folders and apply, So that it will apply based on the API versions.
put themes inside styles.xml. then replicate the styles.xml in values folder for different API levels based folder[based on your requirement you have to create value-X folders] please refer below image.
Upvotes: 0
Reputation: 484
After days of struggling I finally found the problem. my layout was set before calling super.onCreate() and for whatever reason this made Toolbar not apply proper theme in pre-lolipop devices where the native Toolbar is not used.
so I made sure:
setContentView(R.layout.main);
comes after:
super.onCreate(savedinstancestate);
Upvotes: 3
Reputation: 99
hey your have to make the styles files with the version number . For that go to the values and right click and then click the Values Resource file then name the file as styles and then in the dialog under the option available Qualifiers select the version file then press the icon >> and then enter the version 19 on it and this file will work for a version less then Api 21+
this is the dialog you will get on click of value Resource file
this is the final dialog where you need to enter your version number
It might help you.
Upvotes: 0