设置标题背景颜色 [英] Set title background color

查看:184
本文介绍了设置标题背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我想标准/基本标题栏来改变颜色。

In my android application I want the standard/basic title bar to change color.

要更改文本颜色,你有 setTitleColor(INT颜色),有没有办法来改变栏的背景颜色?

To change the text color you have setTitleColor(int color), is there a way to change the background color of the bar?

推荐答案

线程将让你开始建设自己的标题栏在一个XML文件,并在活动使用它

This thread will get you started with building your own title bar in a xml file and using it in your activities

修改

下面是上面的链接的内容的简要概括 - 这是只是设置文字的颜色和标题栏的背景 - 不会进行调整,没有任何按键,只是simpliest样品

Here is a brief summary of the content of the link above - This is just to set the color of the text and the background of the title bar - no resizing, no buttons, just the simpliest sample

RES /布局/ mytitle.xml 的 - 这是一个将重新present视图的标题栏

res/layout/mytitle.xml - This is the view that will represent the title bar

<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/myTitle"
  android:text="This is my new title"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:textColor="@color/titletextcolor"
   />

RES /价值/的themes.xml 的 - 我们要保持默认的Andr​​oid主题,只需要改变的标题背景的背景色。因此,我们创建了一个主题,继承了默认主题和设置背景风格到我们自己的风格。

res/values/themes.xml - We want to keep the default android theme and just need to change the background color of the title background. So we create a theme that inherits the default theme and set the background style to our own style.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="customTheme" parent="android:Theme"> 
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>   
    </style> 
</resources>

RES /价值/ styles.xml 的 - 这是我们设立了主题为使用我们要为标题的背景颜色

res/values/styles.xml - This is where we set the theme to use the color we want for the title background

<?xml version="1.0" encoding="utf-8"?>
<resources> 
   <style name="WindowTitleBackground">     
        <item name="android:background">@color/titlebackgroundcolor</item>                   
    </style>
</resources>

RES /价值/ colors.xml 的 - 在这里设置你想要的颜色

res/values/colors.xml - Set here the color you want

<?xml version="1.0" encoding="utf-8"?>
<resources>   
    <color name="titlebackgroundcolor">#3232CD</color>
    <color name="titletextcolor">#FFFF00</color>
</resources>

的Andr​​oidManifest.xml 的,主题设置属性或者在应用程序(为整个应用程序)或活动(仅限本次活动)标记

In the AndroidMANIFEST.xml, set the theme attribute either in the application (for the whole application) or in the activity (only this activity) tags

<activity android:name=".CustomTitleBar" android:theme="@style/customTheme" ...

从活动(称为CustomTitleBar):

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);

}

这篇关于设置标题背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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