1

我有一个tabhost,里面有一个活动。我希望此活动具有自定义的标题栏,因此我使用了以下代码。但它给出了错误无法将自定义标题与其他标题功能结合起来。我查看文件,只看到一个主题应用于它,我不确定为什么会发生这种情况......知道吗?我还在我的 tabhost 中的其他活动中使用 dialogtheme,但我认为这很好,因为我只将我的自定义主题应用于一个 Activity(名为 startActivity)。

显现:

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainTabActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".StartActivity"
            android:label="@string/app_name"
            android:theme="@style/CustomTheme"   //this is the Custom title bar theme for this activity
            android:screenOrientation="portrait" >
    </activity>

活动 onCreate():

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  //error happned here
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate()");
    setContentView(R.layout.startactivity);

布局文件夹中的 window_title.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="35dip"
    android:gravity="center_vertical"
    android:paddingLeft="5dip"
    android:background="#323331">

    <ImageView
        android:id="@+id/header"
        android:src="@drawable/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

最后,@style:

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

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

0 回答 0