Je reçois android.util.AndroidRuntimeException
lorsque je règle le thème à l'aide de la méthode setTheme
. voici mon code:Erreur lors de la programmation du thème à l'aide de titres personnalisés
@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);
}
}
Déclaration d'activité dans le fichier Manifest:
<activity
android:name=".activities.MenuActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
Je reçois exception suivante lors de l'exécution de ce code avec isCustomScreen
comme vrai:
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
I ont essayé en supprimant la déclaration de thème du fichier manifeste et en réglant t thème qu'il en onCreate
méthode:
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
mais à faire ce que je ne reçois pas l'activité avec un fond translucide lorsque isCustomScreen
comme faux
S'il vous plaît suggérer ce que je devrais faire.
Mise à jour: ajouté des détails sur le thème personnalisé:
<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>
Pouvez-vous poster votre définition de customTitleTheme? Ressemble à ce que je fais normalement. – KarlKarlsom
@KarlKarlsom: j'ai ajouté les détails. – mudit