How do I set the buttons in AlertDialog?

1

I'm having a problem with buttons created in AlertDialog. I'm doing an APP of sentences and at certain times the sentences are very big and causes the buttons in AlertDialog to come down. Is it possible to fix these buttons? Here is an example of what happens: link

My code is this:

// ALERT DIALOG


                    //atributo da classe.

                    //Cria o gerador do AlertDialog
                    AlertDialog.Builder builder = new AlertDialog.Builder(FraseAutorFrase.this);
                    builder.setTitle("O que deseja fazer?");//define o titulo
                    builder.setMessage("\nFrase: " + frasesR [position]);//define a mensagem
                    builder.setView(checkBoxView);

                    //define um botão como positivo
                    builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {

                        }
                    });

                    //define um botão como compartilhar
                    builder.setPositiveButton("Compartilhar", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {

                            Intent sendIntent = new Intent();
                            sendIntent.setAction(Intent.ACTION_SEND);
                            sendIntent.putExtra(Intent.EXTRA_TEXT, frasesR[position] );
                            sendIntent.setType("text/plain");
                            startActivity(sendIntent);
                        }
                    });

                    alerta = builder.create();//cria o AlertDialog
                    alerta.show();//Exibe

Thank you!

    
asked by anonymous 07.06.2017 / 16:25

1 answer

2

You can build a custom layout and put a ScrollView inside it

message_dialog.xml

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/mensagem"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="" />

    </LinearLayout>
</ScrollView>

and then in your Activity you "inflate" this layout and insert into the dialog

LayoutInflater inflater= LayoutInflater.from(this);
View view=inflater.inflate(R.layout.mensagem_dialog, null);

TextView textview=(TextView)view.findViewById(R.id.mensagem);
textview.setText("\nFrase: " + frasesR [position]);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);  
alertDialog.setTitle("O que deseja fazer?");  
alertDialog.setView(view);
alertDialog.setButton("OK", null);  
AlertDialog alert = alertDialog.create();
alert.show();

You can adapt the layout and insert the checkbox to contemplate the favorites, the cool you will have full control of the layout: D

    
07.06.2017 / 17:02