Add a title bar to a theme in Android

257 Views Asked by At

I have a custom title bar set up as a Relative Layout. How would I add it to a theme?

Theme:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomWindowTitleBarBG">
        <item name="android:background">#323331</item>
    </style>

    <style name="TitleBarTheme" parent="android:Theme.DeviceDefault.Light.NoActionBar">
        <item name="android:windowTitleSize">60dip</item>
        <item name="android:windowTitleBackgroundStyle">
            @style/CustomWindowTitleBarBG</item>
    </style>
</resources>

Is there a specific kind of thing I have to add to the theme or do I have to manually add the title bar to every single activity?

1

There are 1 best solutions below

0
Marcin Orlowski On

You cannot use layouts in style. If you want to reuse certain layouts consider either using Fragments or see <merge> and <include> tags you can use in XML: https://developer.android.com/training/improving-layouts/reusing-layouts.html