简体   繁体   English

在Android中为主题添加标题栏

[英]Add a title bar to a theme in Android

I have a custom title bar set up as a Relative Layout . 我有一个自定义标题栏设置为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? 我是否需要在主题中添加某种特定的内容,还是必须将标题栏手动添加到每个活动中?

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 如果要重用某些布局,请考虑使用Fragments或查看可以在XML中使用的<merge><include>标签: https : //developer.android.com/training/improving-layouts/reusing-layouts.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM