25

を表示されません。また、カスタムダイアログフラグメントのタイトル)(示されていない解決されていないアンドロイド6.0ダイアログのテキストは、私は、Android 6.0に自分の携帯電話を更新し、私はダイアログでこれらの2つの問題を抱えている

 new AlertDialog.Builder(context).setTitle("Title").setMessage("Message"); 

2):ロリポップまたは古いバージョンでは、このような問題はありませんでした

 getDialog().setTitle("Title"); 

、問題は自分の携帯電話を更新した後に登場しましたにマシュマロウ。

この問題を解決するにはどうすればよいですか?

+0

あなたのコードをすべて投稿し、あなたは 'show'を呼んではいけません。 –

+0

私はコード – Veka

+0

を編集しました。どこにdialog.show()がありますか? – Rakshith

答えて

1
new AlertDialog.Builder(context) 
    .setTitle("Delete entry") 
    .setMessage("Are you sure you want to delete this entry?") 
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      // continue with delete 
     } 
    }) 
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      // do nothing 
     } 
    }) 
    .setIcon(android.R.drawable.ic_dialog_alert) 
    .show(); 

これは

+0

いいえ、それは働かなかった – Veka

+0

それは私のために働いています.... OKもう一度それをチェックし、あなたに戻ってくる..... – Amaresh

+0

はアプリのターゲットAPI 23ですか? – Veka

0
@Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     // Use the Builder class for convenient dialog construction 
     AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
     builder.setMessage(R.string.dialog_fire_missiles) 
       .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         // FIRE ZE MISSILES! 
        } 
       }) 
       .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         // User cancelled the dialog 
        } 
       }); 
     // Create the AlertDialog object and return it 
     return builder.create(); 
    } 

したら、これは動作します。この希望を確認する.............あなたを助けることを願っています私はあなたが白い背景に白いテキストを表示することに終わっていると思う! (スクリーンショットを見ると、(i)アイコンもうまく表示されず、白以外の背景に表示されるようになっています。

コンストラクタpublic AlertDialog.Builder (Context context, int themeResId)を使用して、 Theme_Material_Dialogはあなたが何をしたいおそらくあなたのダイアログのスタイルをテーマに、ロリポップと新しいアンドロイドのバージョンのテーマに

34

使用コンストラクタ:。

ダークテーマ

AlertDialog.Builder builder; 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert); 
    } else { 
     builder = new AlertDialog.Builder(context); 
    } 

そしてライトのテーマ私の場合は

AlertDialog.Builder builder; 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert); 
    } else { 
     builder = new AlertDialog.Builder(context); 
    } 
+0

ありがとうAlexandr。これは、AlertDialog.Builderのケースでうまく動作します。カスタムダイアログ(ダイアログクラスを拡張し、フラグメントについてではなく)を適用する方法はありますか? – jettimadhuChowdary

+0

@jettimadhuChowdary、カスタムダイアログの使用を作成 'ダイアログ=新CustomDialog(これ、android.R.style.Theme_Material_Dialog_alert);' – Oleksandr

+1

あなたはダイアログの多くを持っている場合、これは良い方法ではありません。 @Stephenの答えは最高です。 –

0

のために、すべてのダイアログがフォント(タイトル&メッセージ)と同じ色を持っていました。私がこの状態を修正するために行ったことは、私のテーマの色属性の変更でした。 xmlのテーマファイルを 'res/values-v22'にコピーし、marshmallowの色を設定しました。

<resources> 
    <style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> 
     <item name="android:textColorPrimary">@android:color/tertiary_text_dark</item> 
    </style> 
</resources> 

またはthemeonCreateDialog()

@NonNull 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     setStyle(STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog_Alert); 
    } 
    Dialog dialog = super.onCreateDialog(savedInstanceState); 
    dialog.setTitle(R.string.dialog_title); 
    return dialog; 
} 
8

回答のために、私たちはただ、内部のファイル、あなたのスタイルでこれを入れonCreateDialog()setStyle()を呼び出す必要がありますあなたのベーステーマのスタイルタグとあなたは良いです

<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item> 
17

で使用されているためだけ2)ためのダイアログ

<resources> 
    <style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> 
     <item name="android:alertDialogTheme">@style/LywAlertDialogStyle</item> 
    </style> 
    <style name="LywAlertDialogStyle" parent="Base.Theme.AppCompat.Light.Dialog.Alert"> 
     <item name="android:textColorPrimary">@color/lyw_secondary_text_color</item> 
    </style> 
</resources> 
+1

私は、このソリューションは、AlertDialogを作成したいあらゆるところで、テーマを確認して変更するよりも優れていると思います。 – SadeghAlavizadeh

6

私は自分のスタイルを作ることでこの問題を解決しようとしました。

あなたのダイアログオブジェクトは次のようであるべきで、あなたのスタイルは、このダイアログが

new AlertDialog.Builder(new ContextThemeWrapper(Context, R.style.Dialog)) 
      .setTitle("Title") 
      .setMessage("Sample Message ...").show(); 

R.style.Dialog ::

<style name="Dialog"> 
    <item name="android:textColorPrimary">@color/primary_text</item> 
    <item name="android:textColor">@color/primary_color</item> 
</style> 

色::の下に書き込まれますと指摘しました

<color name="primary_text">#212121</color> 
<color name="primary_color">#2196f3</color> 

最終的に出力はこのようなものになります

注:: "android:textColorPrimary"はダイアログsetMessageになり、アンドロイドはtextColorがダイアログになりますsetTitle;私はsetPositiveとsetNegativeボタンとリスナをダイアログオブジェクトに使用しませんが、あなた自身のダイアログオブジェクトを作ることができるようにするには、それらを画像で見ることができます。

1

たぶん、あなたのメインのテキストの色は、あなたのstyles.xmlの使用(単なる例)で、その場合には、ダイアログの背景色と同じである:

<style name="AlertDialog" parent="@android:style/Theme.Material.Light.Dialog.Alert"> 
    <item name="android:textColor">#000000</item> 
</style> 

とダイアログの作成中:

new AlertDialog.Builder(
     new ContextThemeWrapper(getContext(), R.style.AlertDialog)) 
).setMessage("test"); 
26

私は、あなたのアプリのテーマに次のように使用すべきであると言ういくつかの答えに遭遇しました:

<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item> 

これは間違いありませんが、すべての場所で機能していませんでした。最終的には、いくつかの場所では、通常のAlertDialogビルダーを使用していて、他の場所ではサポートビルダーを使用していたことに気付きました。あなたがサポートAlertDialogを使用している場合は、必ずまた、あなたのテーマで以下を含めるようにします:

<item name="alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item> 
+3

この回答は一番上にプッシュする必要があります。 – zhaoyuanjie

0

DialogFragmentを使用する場合は、あなたが

  1. する必要性がでスタイル

    <style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog"> 
        <item name="android:windowNoTitle">false</item> 
    </style> 
    
  2. を追加します。あなたのDialogFragment追加getTheme

    public class CustomDialogFragment extends DialogFragment{ 
        public int getTheme() { 
         return R.style.CustomDialogFragment; 
        } 
        . 
        . 
        . 
    

それだけです!