使用自定义标题以程序方式设置主题时出错



当我使用setTheme方法设置主题时,我得到了android.util.AndroidRuntimeException。这是我的代码:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isCustomScreen = getIntent().getBooleanExtra("isCustomScreen", false);
        if (isCustomScreen ) {
            setTheme(R.style.CustomTitleTheme);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        }
        setContentView(R.layout.sample_layout);
            if (isCustomScreen ) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                    R.layout.custom_title_bar);
           }
}

清单文件中的活动声明:

<activity
            android:name=".activities.MenuActivity"
            android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

当使用isCustomScreen作为true运行此代码时,我遇到以下异常:

02-17 18:35:54.619: E/AndroidRuntime(5787): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:183)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2074)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2225)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:194)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at android.app.Activity.setContentView(Activity.java:1647)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.sample.activities.MenuActivity.onCreate(MenuActivity.java:39)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-17 18:35:54.619: E/AndroidRuntime(5787):     ... 11 more

我尝试过从清单文件中删除主题声明并在onCreate方法中设置主题:

setTheme(android.R.style.Theme_Translucent_NoTitleBar);

但在这样做的时候,当isCustomScreenfalse时,我没有得到半透明背景的活动

请建议我该怎么做。

更新:添加了自定义主题的详细信息:

<style name="CustomWindowTitleBackground">
        <item name="android:background">#000000</item>
    </style>
    <style name="CustomTitleTheme" parent="Theme">
        <item name="android:windowTitleSize">45dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>
<i><application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        //do not write theme setting here 
        android:label="@string/app_name" >
        <activity
            android:name=".activity.loginPageActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" //set theme here
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".activity.HomePageFragmentActivity" >
        </activity>
</application></i>

相关内容

  • 没有找到相关文章

最新更新