2016-12-26 15 views
2

AlertDialogueテーマを設定するか、の変更を背景色に設定します。アラートダイアログの背景テーマ/色

デフォルトのテーマがありますが、別のバージョンでは異なるテーマになっていますので、すべてのバージョンで修正したいと思っています。

それとも単に白

@NonNull 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     final SimpleAdapter adapter = new SimpleAdapter(getContext(), imagesWithNames, R.layout.lib_dialog_image, 
       new String[]{"name", "imageID","Spacing"}, new int[]{R.id.text1, R.id.image1,R.id.spacing}); 
     return new AlertDialog.Builder(getContext()).setAdapter(adapter, 
       new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialogInterface, int i) { 
         ((PlaceCallActivity) getContext()).OnSelected(WithNamesFragment.this.getClass(), (int) ((HashMap<String, Object>) adapter.getItem(i)).get("imageID")); 
        } 
       }).setCancelable(true).setTitle("PICK YOUR AVATAR").setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       dialog.dismiss(); 
      } 
     }).create(); 
    } 

と背景色を変更するには、あなたのコードを投稿しないでください、私はここに変更を加える必要がある場所を教えてください。

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom)); 

注:上記の行は、それを行うだろうが、私は私のAlertDialogue

enter image description here

+0

あなたはまだ解決策をお探しですか? –

+0

はい私はまだ1つを見つけませんでした! – SamH67

+0

これを参照してくださいhttp://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog –

答えて

5

を次のようにあなたのstyles.xmlファイルであなたのスタイルを作成します。 ContextThemeWrapperクラスのコンストラクタに現在のクラスのコンテキストとスタイルを渡し

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(NewCase.this, R.style.AlertDialogCustom)); 

ここでは、次のようにBuilderを使用して

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog"> 
     <item name="android:textColor">@color/White</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:headerDividersEnabled">true</item> 
     <item name="android:typeface">normal</item> 
     <item name="android:background">@color/colorPrimaryDark</item> 
    </style> 

次に作成しますAlert Dialog

+0

最初に見て、私がそこで何をすべきか教えてください私のリターンダイアログにこれを追加できませんAnkit Shahは正しくやっていますが、問題があります。 – SamH67

+0

@ SamH67あなたが何をしたいのか正確に教えてください。それから私はあなたを助けることができます。 –

+0

あなたのコードを追加することができないので、自分のやりたいことです。私のコードを見て、追加する方法を教えてください。私はすでにこのことを知っているので、この質問を投稿する前に私はすでにこの事を試してきたので、それを行う前に試してみてください。その返信文の中でテーマを変更することができます – SamH67

2

のスタイルを与えるべき場所がダイアログスタイル内部のres /値/スタイルを追加する必要が知りたいです.xml。以下のように。

<style name="MyDialog" parent="@android:style/Theme.Holo.Light.Dialog"> 
     <item name="android:background">@color/white</item> 
    </style> 

またはあなたはまた、以下のように背景色を変更する:

EDIT:

getWindow().setBackgroundDrawableResource(R.color.white); 
+0

getWindowを解決できません – SamH67

+0

@ SamH67私の答えは更新されています。 –