2014-10-29 4 views
1

android 테마와 관련된 문제를 해결하려면 가이드가 필요합니다.AlertDialog 테마를 바꿀 수 없습니다.

사용자 지정 테마를 경고 대화 상자에 적용하기 위해 사용자 지정 테마를 만들었습니다. 그러나 ContextThemeWrapper를 사용하여 실제 대화 상자에 적용하려고하면 android.R.style.MyTheme이 인식되지 않습니다. 나는 R.에서 볼에도 불구하고, android.R.style.Mytheme 분명히 존재하지 않기 때문에 오류가 발생하는이 라인에서

// 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; 
    } 

: 여기

는 MainActivity.java 안에 내 코드입니다 자바 파일.

AlertDialog.Builder checkboxDialogBuilder = new AlertDialog.Builder (새 ContextThemeWrapper (getActivity(), android.R 스타일의 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; 
} 

그리고는 고해상도/값/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> 

감사합니다!

답변

1
AlertDialog.Builder checkboxDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.MyTheme)); 

액세스하는 자원은 위의 해결책을 시도해보십시오.

+0

아, 이제 왜 실패했는지 이해합니다. – nanonymous

1

내가 누락 된 내용이 없으면 android.R.style.MyThemeR.style.MyTheme이어야합니다. 현재 당신은 안드로이드의 리소스가 아닌 스타일 MyTheme을 참조하려고합니다.

관련 문제