Мне нужен какой-нибудь руководство для решения проблемы с темами Android.Я не могу изменить свою тему AlertDialog
Я создал пользовательскую тему, чтобы применить ее к диалоговому оповещению. Все кажется прекрасным и денди, однако, когда я пытаюсь применить его к фактическому диалоговому окну с помощью ContextThemeWrapper, андроид.R.style.MyTheme не распознается.
Вот мой код внутри MainActivity.java:
// Build CheckBox Dialog
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder checkboxDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(),
android.R.style.MyTheme));
checkboxDialogBuilder
.setTitle("Pick the colors")
.setSingleChoiceItems(items, -1,
new DialogInterface.OnClickListener() {
// indexSelected contains the index of item (of which checkbox checked)
@Override
public void onClick(DialogInterface dialog, int item) {
switch(item)
{
case 0:
// RGB choice
RGB = true;
break;
case 1:
// CMY choice
RGB = false;
break;
}
}
})
// Set the action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// user clicked on OK
setColorModeBackground();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// user clicked on Cancel
mDialog.dismiss();
}
});
AlertDialog customCheckboxDialog = checkboxDialogBuilder.create();
customCheckboxDialog.show();
return customCheckboxDialog;
}
В этой строке я получаю сообщение об ошибке, потому что android.R.style.Mytheme не существует, по-видимому, даже если я вижу его в R. java-файл.
AlertDialog.Builder checkboxDialogBuilder = new AlertDialog.Builder (новый ContextThemeWrapper (getActivity(), android.R.style.MyTheme));
R.java файл:
public static final class style {
/**
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
API 11 theme customizations can go here.
*/
public static final int AppBaseTheme=0x7f060000;
/** Application theme. All customizations that are NOT specific to a
particular API-level can go here.
*/
public static final int AppTheme=0x7f060001;
public static final int MyTheme=0x7f060007;
/**
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
*/
public static final int base=0x7f060002;
public static final int body=0x7f060004;
public static final int customDialogTheme=0x7f060005;
public static final int dialogTheme=0x7f060006;
public static final int title=0x7f060003;
}
А вот файл в RES/значений/styles.xml:
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="MyTheme" parent="AppBaseTheme">
<item name="android:alertDialogStyle">@style/customDialogTheme</item>
</style>
<style name="customDialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:alertDialogStyle">@style/customDialogTheme</item>
<item name="android:fullDark">@drawable/dialog_body</item>
<item name="android:topDark">@drawable/dialog_title</item>
<item name="android:centerDark">@drawable/dialog_body</item>
<item name="android:bottomDark">@drawable/dialog_footer</item>
<item name="android:fullBright">@drawable/dialog_body</item>
<item name="android:centerBright">@drawable/dialog_body</item>
<item name="android:bottomBright">@drawable/dialog_footer</item>
<item name="android:bottomMedium">@drawable/dialog_footer</item>
<item name="android:centerMedium">@drawable/dialog_body</item>
</style>
заранее спасибо!
А теперь я понимаю, почему это было неудачно. – nanonymous