2017-10-12 6 views
0

Je travaille sur une application dans laquelle j'appelle une boîte de dialogue de mon fragment sur un clic de bouton mais mon problème est que lorsque je clique sur un bouton, une boîte de dialogue apparaît mais s'affiche en couleur terne . Et quand je clique à nouveau sur le dialogue alors son arrière-plan change en couleur blanche. Donc, je veux juste savoir pourquoi ça se passe comme ça.Impossible d'afficher la boîte de dialogue correctement

code pour appeler la fenêtre du fragment sur le bouton cliquez

 sms = (ImageView) v.findViewById(R.id.sms); 
    sms.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      if (!admin_id.equals("0") && status.equals("A")) { 
       DialogSMS dialogSMS = new DialogSMS(getActivity(), getContext()); 
       dialogSMS.show(); 
      } else { 
       Toast.makeText(getActivity(), getResources().getString(R.string.disable_click), Toast.LENGTH_SHORT).show(); 

      } 

     } 

    }); 

code Dialog

public class DialogSMS extends Dialog { 

Context context; 
ProgressDialog progressDialog; 
SharedPreferences sharedPreferences; 
SharedPreferences.Editor editor; 
public static final String MY_PREF = "pref"; 
public static final String IS_SMS_SUBSCRIBE = "sms_status"; 
EditText etPostalCode; 
EditText phoneNumber; 
Dialog d; 


public DialogSMS(Activity a, Context context) { 
    super(a); 
    this.context = context; 
} 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setBackgroundDrawableResource(android.R.color.transparent); 
    progressDialog = new ProgressDialog(context); 

    sharedPreferences = context.getSharedPreferences(MY_PREF, Context.MODE_PRIVATE); 

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); 
    alertDialog.setMessage(R.string.app_sms_dialog_msg); 
    alertDialog.setPositiveButton(R.string.app_close_dialog_msg_yes, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 

      SessionManager session = new SessionManager(context); 

      if (session.isSmsSubscribed()) { 

       AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); 
       alertDialog.setMessage(R.string.app_sms_unsubscribe); 
       alertDialog.setPositiveButton(R.string.app_close_dialog_msg_yes, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 

         unSubscribeSMS(); 
         dialog.cancel(); 
        } 
       }); 
       alertDialog.setNegativeButton(R.string.app_close_dialog_msg_no, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         dialog.cancel(); 
        } 
       }); 
       alertDialog.show(); 


      } else { 
       d = new Dialog(getContext()); 
       d.setContentView(R.layout.dialog_select_sms); 
       etPostalCode = (EditText) d.findViewById(R.id.etPostalCode); 
       phoneNumber = (EditText) d.findViewById(R.id.phoneNumber); 


       Button btnSend = (Button) d.findViewById(R.id.btnSend); 
       d.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 

       btnSend.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 


         String mobile = phoneNumber.getText().toString(); 
         String postalCode = etPostalCode.getText().toString(); 

         validateFields(mobile, postalCode); 

         //subscribeSMS(postalCode, mobile); 
         // d.cancel(); 
        } 
       }); 
       d.show(); 
       dialog.cancel(); 

      } 
     } 
    }); 
    alertDialog.setNegativeButton(R.string.app_close_dialog_msg_no, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      dialog.cancel(); 
     } 
    }); 
    alertDialog.show(); 
} 

Et maintenant lien capture d'écran pour dialogue lors de la première apparaît

en capture d'écran noir Ouvrir une fenêtre pop-up:

enter image description here

dialogue blanc quand cliquez sur dialogue nouveau:

enter image description here

Répondre

0

Utilisation dialog.dismiss() au lieu de dialog.cancel()

1

Je veux juste savoir pourquoi cela se produit comme cette

Ici,

DialogSMS dialogSMS = new DialogSMS(getActivity(), getContext()); 
dialogSMS.show(); 

affiche un dialogue et à l'intérieur de DialogSMS vous créez également AlertDialog et montrant encore,

AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); 
alertDialog.setMessage(R.string.app_sms_dialog_msg); 
-------------------------- 
alertDialog.show(); 

Lorsque vous cliquez sur boîte de dialogue des son annulation sur des dialogues .

Vous n'avez pas besoin de créer AlertDialog dans DialogSMS.

Si vous avez besoin d'AlertDialog, alors pourquoi vous affichez Dialog?

* Cela pourrait vous aider - * Il suffit d'apporter votre condition si-autre à l'intérieur

sms.setOnClickListener

et montrer votre désir AlertDialog