标题栏颜色变化问题 [英] Title bar color change issues
本文介绍了标题栏颜色变化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要动态地更改标题栏的颜色,即:用户点击一个按钮,它改变了颜色。不过,我似乎无法得到它填满整个标题栏。这发生在这两个模拟器和Nexus One的。任何想法?
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android机器人:ID =@ + ID / title_bar机器人:背景=@色/ title_bar_blue机器人:layout_width = FILL_PARENT机器人:layout_height =FILL_PARENT>
< TextView的Android的:机器人:ATTR / windowTitleStyle:ID =@ + ID / title_left_text机器人layout_alignParentLeft =真的风格=机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT/>
< TextView的Android的:机器人:ATTR / windowTitleStyle:ID =@ + ID / title_right_text机器人layout_alignParentRight =真的风格=机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT/>
< / RelativeLayout的>
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
的setContentView(R.layout.main);
。getWindow()setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
标题栏的=(RelativeLayout的)findViewById(R.id.title_bar);
titleBar.setBackgroundResource(R.color.title_bar_green);
解决方案
试试这个((查看)titleBar.getParent())setBackgroundColor(R.color.title_bar_green);
这不是做这项工作的最佳途径。但是,如果一切正常,那么你就会知道,你需要设置背景颜色 R.id.title_bar
父。
I want to change the color of the title bar dynamically, ie: someone clicks a button, it changes the color. However, I can't seem to get it to fill the entire title bar. This occurs on both the emulator and a Nexus One. Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/title_bar" android:background="@color/title_bar_blue" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/title_left_text" android:layout_alignParentLeft="true" style="?android:attr/windowTitleStyle" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/title_right_text" android:layout_alignParentRight="true" style="?android:attr/windowTitleStyle" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</RelativeLayout>
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
titleBar = (RelativeLayout) findViewById(R.id.title_bar);
titleBar.setBackgroundResource(R.color.title_bar_green);
解决方案
Try this ((View) titleBar.getParent()).setBackgroundColor(R.color.title_bar_green);
It is not the best way to do the job. But if it works, then you will know that you need to set background color of R.id.title_bar
parent.
这篇关于标题栏颜色变化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文