- 創建一個新的項目,並命名您的主要活動「MyActivity」
轉到資源 - 繪製並創建一個新的XML文件,並把它稱爲「custom_title_background」,並把下面的代碼:
<item android:top="20dp">
<shape android:shape="rectangle">
<gradient android:angle="90" android:endcolor="#9eacbf" android:startcolor="#8296af">
</gradient></shape>
</item>
這可繪製將用於設置背景從custom_title_bar(來自步驟3),並設定windowTitleBackgroundStyle從custom_title_style(來自步驟4 )
轉到res-layout並創建一個新的xml並將其命名爲「custom_title_bar」。在這裏,您將創建一個佈局,就像下面代碼的文本視圖:
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:id="@+id/custom_title_text"
android:layout_centerInParent="true"
android:shadowColor="@android:color/black"
android:shadowRadius="3"/>
轉到資源 - 值,並創建一個新的XML文件,並custom_title_style調用它。在這裏,您將通過覆蓋現有主題來創建新主題。從下面的風格「custom_title_theme」的名稱將被用於清單文件中以「激活」新的主題。
40dp @繪製/ custom_title_background
現在去AndroidManifest.xml文件,並把新的主題應用標籤。
?
而在這最後一步,你必須去MyActivity類,並把下面的代碼:
進口android.app.Activity; import android.os.Bundle; import android.view.Window; import android.widget.TextView;
公共類MyActivity延伸活動{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this must be called BEFORE setContentView
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
//this must bew called AFTER setContentView
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
//set the title
TextView textView = (TextView)findViewById(R.id.custom_title_text);
textView.setText("Custom Title");
}
}
這意味着很多。謝謝 – AdityaSetyadi 2012-01-11 21:40:14