0

J'ai besoin d'une boîte de dialogue personnalisée, très similaire à celle affichée pour l'autorisation USB DEBUG. Je suis sur API NIVEAU 15 et plus. DEBUG AUTH DIALOG Fondamentalement, je dois mettre une case à cocher avec un texte dans la vue personnalisée. J'ai essayé:Fragment de boîte de dialogue Corps personnalisé Case à cocher

LayoutInflater inflater = getActivity().getLayoutInflater(); 
builder.setView(inflater.inflate(R.layout.my_dialog, (ViewGroup) getActivity().findViewById(R.id.root_of_my_dialog))); 

Et mon avis personnalisé est:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root_of_my_dialog" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <!-- Here I'll have the checkbox --> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Test" 
     android:textColor="@color/red" /> 

</LinearLayout> 

De cette façon, ma mise en page personnalisée ne reçoit pas la marge de droite/padding (le mot test est juste à l'extrême gauche) ... c'est juste comme ne pas avoir de style. Comment puis-je hériter de la norme/par défaut?

Répondre

0

La création d'une boîte de dialogue a déjà été répondue. Lire les liens ci-dessous:

  1. create-a-custom-dialog-box-in-android

  2. create-modal-dialog-box-in-android

Hope this helps.

+0

Je ne pas besoin d'un dialogue nouveau personnalisé tout, j'ai juste besoin d'ajouter un corps avec une case à cocher. Je voudrais rester "standard". – Jumpa

+0

Vérifiez le deuxième lien. C'est la même réponse que dieter_h. –

+0

J'utilise déjà une boîte de dialogue d'alerte, j'ai les boutons Titre, Message, Négatif et Positif, la seule chose qui me manque est un corps personnalisé avec une case à cocher. – Jumpa

0

Essayez ceci:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    // Get the layout inflater 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    View v = inflater.inflate(R.layout.my_dialog, null); 
    builder.setView(v) 
    // Add action buttons 
      .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int id) { 
        // OK 
       } 
      }) 
      .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        //cancel 
       } 
      }); 


    Dialog dialog = builder.create(); 
    dialog.show(); 

Ajouter padding

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root_of_my_dialog" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="20dp" 
    android:orientation="vertical"> 

    <!-- Here I'll have the checkbox --> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Test" 
     android:textColor="#ff0000" /> 

</LinearLayout> 
+0

Votre indice passe null comme vue parent? Si c'est le cas, cela ne fonctionne pas. :( – Jumpa

+0

Mon code fonctionne très bien, je l'ai testé –

+0

Donc, le texte est correctement placé? Êtes-vous sur Lollipop? – Jumpa