2011-03-05 41 views

回答

0

这是一个真正的解决方法,但我得到了我wanted.I把一个TextView在我的布局的顶部,获得以下尺寸,使它看起来像一个标题栏

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/vehicle_view" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

//Title bar 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="24dip" 
    android:id="@+id/title_bar_text" 
    android:background="#dddddd" 
    android:textColor="#150517" 
    android:text="Enter Text"> 
</TextView> 
............................. //Rest of layout elements 
............................. 
............................. 
</LinearLayout> 

如果有人得到了一个更好的答案,以某种方式添加一个额外的标题栏,而不会像我做的那样改变布局发布它,我会接受作为答案。

0

thread将让你开始在你的活动构建自己的标题栏的XML文件,并使用它

这里是上面的链接的内容的简要概括 - 这只是设置颜色文本和标题栏的背景的 - 没有调整尺寸,没有按钮,就在simpliest样品

RES /布局/ mytitle.xml - 这是将代表标题栏

<?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.x ml - 我们想保留默认的Android主题,只需要改变标题背景的背景颜色。所以我们创建一个主题,继承默认的主题,并将背景样式设置为我们自己的样式。

<?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 - 这是我们设定的主题中使用我们想要的颜色为标题背景

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

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

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

在AndroidManifest.xml中,设置在应用程序(为整个应用程序)的主题,无论是属性还是在活动(仅限本次活动)标签

<activity android:name=".CustomTitleBar" android:theme="@style/customTheme" ... 
From the Activity (called 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); 

} 
+0

这是您对“简要”摘要的想法吗? :p – 2011-03-05 09:12:14

+0

我已经看到这在http://stackoverflow.com/questions/2251714/set-title-background-color/2251787#2251787。这是为了自定义标题栏。我正在通过框架寻找一个选项来添加一个额外的标题栏.. – rogerstone 2011-03-05 11:23:56

相关问题