Alertdialog, separate the title of the message

2

I am using the Holo_Dialog theme in an AlertDialog, the problem is that the title comes out below the line of separation, how could I put the title above ?, or if I use the theme Theme_AppCompat_Dialog_MinWidth, how could I separate the title from menasaje? attached photos

this is the alertDialog with the holo theme, how can I get the title out above the line?

this is the alertdialog with the topic Theme_AppCompat_Dialog_MinWidth, how can I make the title and the text separated by a line?

this is the code for theme Theme_Holo_Dialog

   public void alertDialogExtraerBase() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_Holo_Dialog);
        builder.setIcon(R.drawable.extraer);
        builder.setTitle("EXTRAER BASE?")
                .setCancelable(false)
                .setMessage("Se hara una copia de la base de datos, se guardara en la memoria interna del dispositivo, en la carpeta 'BACKUPSERIES'");
        builder.setPositiveButton("ACEPTAR", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                extraer.extraerbase(MainActivity.this);
            }
        });
        builder.setNegativeButton("CANCELAR", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.show();
    }

this is the code for theme Theme_AppCompat_Dialog_MinWidth

    public void alertDialogImportarBase() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Theme_AppCompat_Dialog_MinWidth);
        builder.setIcon(R.drawable.importar);
        builder.setTitle("IMPORTAR BASE?")
                .setCancelable(false)
                .setMessage("Asegurate que tienes una copia de la base guardada en la carpeta 'BACKUPSERIES'");
        builder.setPositiveButton("ACEPTAR", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                importar.importarbase(MainActivity.this);
            }
        });
        builder.setNegativeButton("CANCELAR", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.show();
    }

can someone help me? thanks

    
asked by Jose Joaquin 04.03.2018 в 01:38
source

1 answer

4

It seems that there is some problem with that theme that does not allow the title to be above the dividing line. Even so, you can create a specific layout for that or any other theme with a custom header.

To do this you must change the AlertDialog to customize it to your liking in MainActivity as follows:

// Tu constructora como la tenias
AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_Holo_Dialog_MinWidth)
    .setTitle("EXTRAER BASE?")
    .setCancelable(false)
    .setMessage("Se hara una copia de la base de datos, se guardara en la memoria interna del dispositivo, en la carpeta 'BACKUPSERIES'")
    .setPositiveButton("ACEPTAR", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            extraer.extraerbase(MainActivity.this);
        }
    })
    .setNegativeButton("CANCELAR", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {

     }
});

// Asociamos el layout personalizado
Context mContext = builder.getContext();
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
View mView = mLayoutInflater.inflate(R.layout.cabezera_dialog, null);
TextView mTextView = (TextView) mView.findViewById(R.id.title_text);
mTextView.setText("EXTRAER BASE?");
builder.setCustomTitle(mView);

// Quitamos la cabezera del propio AlertDialog
AlertDialog alertDialog = builder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.show();

And we create our% custom cabezera_dialog.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="15dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="15dp">

    <TextView
        android:id="@+id/title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:maxLines="1"
        android:textAlignment="center"
        android:textColor="@android:color/holo_blue_dark"
        android:paddingTop="15dp"
        android:paddingBottom="15dp"
        android:textSize="16sp"
        android:textStyle="bold" />

    <View
        android:layout_width="wrap_content"
        android:layout_height="2dp"
        android:background="@android:color/holo_blue_dark"/>

</LinearLayout>

With the following result:

And from there you can customize the header in the layout that we have created ( cabezera_dialog.xml ) to our liking.

This is applicable for any of the two themes with which you had problems and for anyone that we want.

    
answered by 04.03.2018 / 05:03
source