我在使用android.util.AndroidRuntimeException
方法设置主题时收到setTheme
。这是我的代码:
@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);
但在执行此操作时,isCustomScreen
为 false
请建议我该怎么做。
更新:添加了自定义主题的详细信息:
<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>
答案 0 :(得分:0)
<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>