I have a AppCompat21 Appbar/Toolbar in almost all of my Activities. All activities layout files have the following in common:
<!-- material design actionbar & toolbar -->
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
so instead of having to add these attributes all the time:
android:theme="@style/AppTheme.AppBarOverlay"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"
I'm trying to find out how to redefine the appbar/toolbar look and feel in a global fashion within my app so I don't need this piece of redundant code everywhere.
Is this even possible? I have done it for the button style, but I can't get my head around this one...
You can create a layout resource file containing your toolbar, named 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"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
and in your activities you can just simply do
<include layout="@layout/toolbar" android:id="@+id/toolbar">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With