1

スタイルを使用してカスタム テーマを定義する場合:

<style name="MyTheme" parent="android:Theme">
    <item name="android:windowTitleSize">@dimen/title_bar_height</item>
    <item name="android:windowTitleBackgroundStyle">@drawable/titilebar_bg</item>
    <item name="android:windowBackground">@drawable/bg_page</item> 
</style>

また、タイトル バー (ボタン、アイコン、テキストなど) を定義する特別なtitlebar.xmlものがあります。このレイアウトをスタイルのタイトル バーの既定のレイアウトとして設定する方法はありますか (すべてのアクティビティの既定の動作など)。

そのため、すべてのアクティビティ (実際にはすべてのアクティビティ) に次のコードを追加する必要はありません。

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);

私が見ることができる唯一の方法は、アクティビティをサブクラス化して、onCreate()/setContentView() の中で requestWindowFeature() を作成するメソッドを継承することです。しかし、それはまさに私が求めていることではありません。

4

1 に答える 1

0

Styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <style name="CustomWindowTitleBackground">
        <item name="android:background">#000000</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">35dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>
</resources>       

Mainfest.xml

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
于 2013-04-15T11:36:53.980 に答える