Diálogos de alerta de diseño de material no estilizado


He agregado el diseño de material AppCompat a mi aplicación y parece que los diálogos de alerta no están usando mis colores primarios, primaryDark o accent.

Aquí está mi estilo base:

<style name="MaterialNavyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/apptheme_color</item>
    <item name="colorPrimaryDark">@color/apptheme_color_dark</item>
    <item name="colorAccent">@color/apptheme_color</item>
    <item name="android:textColorPrimary">@color/action_bar_gray</item>
</style>

Según mi comprensión, el texto del botón de diálogo también debe usar estos colores. ¿Me equivoco a mi entender o hay algo más que tengo que hacer?


Solución:

La respuesta marcada me puso en el camino correcto.

<style name="MaterialNavyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/apptheme_color</item>
    <item name="colorPrimaryDark">@color/apptheme_color_dark</item>
    <item name="colorAccent">@color/apptheme_color</item>
    <item name="android:actionModeBackground">@color/apptheme_color_dark</item>
    <item name="android:textColorPrimary">@color/action_bar_gray</item>
    <item name="sdlDialogStyle">@style/DialogStyleLight</item>
    <item name="android:seekBarStyle">@style/SeekBarNavyTheme</item>
</style>

<style name="StyledDialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/apptheme_color</item>
    <item name="colorPrimaryDark">@color/apptheme_color_dark</item>
    <item name="colorAccent">@color/apptheme_color</item>
</style>
Author: Richard Le Mesurier, 2014-10-20

7 answers

Con el nuevo AppCompat v22.1 puedes usar el nuevo android.apoyo.v7.app.AlertDialog .

Simplemente use un código como este:

import android.support.v7.app.AlertDialog

AlertDialog.Builder builder =
       new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
            builder.setTitle("Dialog");
            builder.setMessage("Lorem ipsum dolor ....");
            builder.setPositiveButton("OK", null);
            builder.setNegativeButton("Cancel", null);
            builder.show();

Y usa un estilo como este:

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">#FFCC00</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:background">#5fa3d0</item>
    </style>

De lo contrario, puede definir en su tema actual:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- your style -->
    <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>

Y luego en su código:

 import android.support.v7.app.AlertDialog

    AlertDialog.Builder builder =
           new AlertDialog.Builder(this);

Aquí el AlertDialog en Kitkat: introduzca la descripción de la imagen aquí

 438
Author: Gabriele Mariotti,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-04 12:53:25

Al inicializar dialog builder, pase el segundo parámetro como tema. Mostrará automáticamente material design con API nivel 21.

AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK);

O

AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
 7
Author: Sandeep Kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-28 15:36:28

AppCompat no hace eso para los diálogos (al menos no todavía)

EDITAR: lo hace ahora. asegúrese de usar android.support.v7.app.AlertDialog

 4
Author: nadavfima,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-19 11:38:40

Puedes considerar este proyecto: https://github.com/fengdai/AlertDialogPro

Puede proporcionarte diálogos de alerta de tema de material casi iguales a los de lollipop. Compatible con Android 2.1.

 2
Author: Feng Dai,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-06 01:52:55

Podrías usar

Biblioteca de Diseño de Materiales

Material Design Library hecho para bonitos diálogos de alerta, botones y otras cosas como barras de aperitivos. Actualmente está muy desarrollado.

Guía, código, ejemplo - https://github.com/navasmdc/MaterialDesignLibrary

Guía cómo agregar biblioteca a Android Studio 1.0 - Cómo puedo importar la biblioteca de material design a Android ¿Estudio?

.

Feliz codificación;)

 2
Author: Inoy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:07

Prueba esta biblioteca:

Https://github.com/avast/android-styled-dialogs

Se basa en DialogFragments en lugar de AlertDialogs (como el de @afollestad). La principal ventaja: Los diálogos no se descartan después de la rotación y las devoluciones de llamada siguen funcionando.

 1
Author: David Vávra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-08 14:36:47

Por alguna razón, android:textColor solo parece actualizar el color del título. Puede cambiar el color del texto del mensaje usando un

SpannableString.AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.MyDialogTheme));

AlertDialog dialog = builder.create();
                Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers");
                wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                dialog.setMessage(wordtoSpan);
                dialog.show();
 1
Author: CaptRespect,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-06 16:56:09