2011-03-05 72 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

相關問題