2016-07-27 21 views
6

Uygulamamdaki ses talimatlarını indirmek için kullanacağım bir popup'ım var. Yapmaya çalıştığım şey, "OK" nin varsayılan metin rengini maviye değiştirmek istiyorum. Bir şey denedim ama çalışmıyor. İşte benim kodudur:Uyarı iletişim kutusunun metin rengini değiştirme

private void showDownloadPgmPopup() { 

    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity()); 
    builder.setTitle("Download instructional audio?"); 
    builder.setMessage(ParamConstants.AUDIODOWNLOADPERMISSION); 
    builder.setNegativeButton("No", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      WwDatabaseHelper.storeSelectedWeekAndDay(getActivity(), mSelectedWeekDataModel); 
      goToMoveScreen(); 
     } 
    }); 
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      AndroidDownloadFileByProgressBarActivity.StartAudioAssetDownload(getActivity()); 

     } 

    }).create(); 
    // change the text color of download instruction ok button 


    final android.app.AlertDialog dialog = builder.show(); 
    dialog.setOnShowListener(new DialogInterface.OnShowListener() { 
            @Override 
            public void onShow(DialogInterface arg0) { 
             dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#ff5722")); 
            } 
           }); 
    dialog.setCanceledOnTouchOutside(false); 
    dialog.show(); 
} 

Ama değişim kimse ben yanlış yapıyorum bana söyleyebilir yansıtan değil?

+0

Olası yinelenen [Nasıl android'de Özel İletişim kutusu oluşturmak için?] (Http: // st) ackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android) – SaravInfern

cevap

2

Bu

  1. sebep olduğu varsayılan iletişim yapmak için iki yol vardır.
//1. create a dialog object 'dialog' 
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Exit", errorMessage); 
AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 
        ... 
       } 

      }).create(); 
//2. now setup to change color of the button 
dialog.setOnShowListener(new OnShowListener() { 
    @Override 
    public void onShow(DialogInterface arg0) { 
     dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.parseColor("#f34235")); 
    } 
} 

dialog.show() 
  1. Kendi custom iletişim
// create instance of dialog 
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); 

// get inflater and inflate layour for dialogue 
LayoutInflater inflater = this.getLayoutInflater(); 
View dialogView = inflater.inflate(R.layout.alert_label_editor, null); 

// now set layout to dialog 
dialogBuilder.setView(dialogView); 

// create instance like this OR directly mentioned in layout 
Button button= (Button) dialogView.findViewById(R.id.label_field); 
button.setText("test label"); 
AlertDialog alertDialog = dialogBuilder.create(); 

// show dialog 
alertDialog.show(); 
5

Uyarı İletişim Kutusu tam özelleştirme here oluşturun.

Örnek:

enter image description here

6

Sen AlertDialog yapıcı bir özel stil kimliği sağlamak zorunda:

AlertDialog.Builder(Context context, int themeResId) 

ve olmalıdır stil dosyası gibi bir şey:

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="android:colorAccent">#0000FF</item> 
</style> 
İlgili konular