Difference between alertDialogStyle and alertDialogTheme

4

Well the title is very clear, what is the difference between alertDialogStyle and alertDialogTheme ?

I have been looking at the documentation of Android developers but it is not very clear to me, could you explain it to me better?

<resources>
    <style name="PLMS_Style" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="android:actionBarStyle">@style/MyToolbar</item>
        <item name="android:actionBarTheme">@style/MyToolbar</item>
    </style>
    <style name="MyToolbar">
        <item name="android:colorBackground">@color/black</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorPrimaryInverse">@color/primary_text_material_dark</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:textColorSecondaryInverse">@color/secondary_text_material_light</item>
    </style>
</resources>

In this case I would have to use, Style or Theme?

    
asked by borjis 17.10.2016 в 18:05
source

1 answer

3

This question is interesting, a title like

would be appropriate

"Difference between Style and Theme".

Styles and Themes is applied not only for AlerDialog , applies to any type of view, TextView, EditText, Button, ImageView, etc ...

  

Style : (in Spanish "Style"), is a collection of properties such as colors, fonts, effects, sizes, background, etc. what   define the appearance of a view.

<TextView
    style="@style/myStyle"
    android:text="Hola StackOverflow.com" />
  

Theme : (in Spanish "Tema"), Unlike Style, the Theme is applied to the whole Activity, not only to one view, therefore the properties are   inherited to the views that the Activity contains, all the elements that are contained will adopt the Style defined by the Theme .

<activity  android:name="MainActivity"
android:theme="@style/myTheme">

In the case of Android the theme can be applied to all the Activities of your application.

  <application
        android:label="Stackoverflow.con app"
        android:theme="@style/myTheme">

Example defining a Theme for AlerDialog:

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle);
builder.setTitle("my AlertDialog");
builder.setMessage("Hola StackOverflow.com!");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();

where MyAlertDialogStyle is:

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <!-- Used for the buttons -->
    <item name="colorAccent">#AACC12</item>
    <!-- Used for the title and text -->
    <item name="android:textColorPrimary">#FFFFFF</item>
    <!-- Used for the background -->
    <item name="android:background">#12AAF1</item>
</style>
    
answered by 18.10.2016 / 01:46
source