在 Android 中创建自定义标题栏 [英] Create custom titlebar in Android

查看:24
本文介绍了在 Android 中创建自定义标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序创建了一个自定义标题栏,但我在实现它时遇到了一些问题.我想更改文本和标题栏的颜色和外观

I created a custom title bar for my application but I am having some problems implementing it. I want to change the color and the appearance for the text and title bar

styles.xml 的布局如下:

The layout of the styles.xml is as below:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="MyTheme">
    <item name="android:tabWidgetStyle">@style/LightTabWidget</item>


</style>
<style name="MyWindowTitleBackground" parent="@android:style/WindowTitleBackground">
    <item name="android:background">@android:drawable/title_bar</item>

</style>

<style name="MyWindowTitle" parent="@android:style/WindowTitle">
    <item name="android:singleLine">true</item>
    <item name="android:windowTitleSize">40dip</item>
    <item name="android:textAppearance">@style/MyTextAppearance</item>
    <item name="android:shadowColor">#BB000000</item>
    <item name="android:shadowRadius">2.75</item>
</style>
 <style name="MyTextAppearance" parent="@android:style/TextAppearance.WindowTitle">
    <item name="android:textColor">#3A6629</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="LightTabWidget" parent="@android:style/Widget.TabWidget">

    <item name="android:textSize">20px</item>
    <item name="android:textStyle">bold</item>

    <item name="android:textColor">#FF5721</item>
</style>
</resources>

我在清单文件中添加了该主题,如下所示:

And I have added that theme in the manifest file as follows:

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light">
   <activity android:name="LAFoodBankAboutUs" android:label="@string/app_name" android:theme="@style/MyTheme">

我必须做什么才能显示自定义标题栏?

What do I have to do to show the custom title bar?

推荐答案

到现在(几年后),工具栏 可用.它具有很多 自定义 可能性,也可以通过支持库

By now (after some years), the Toolbar is available. It features a lot of customization possibilities and is also available via the Support Library

这篇关于在 Android 中创建自定义标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆