CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2019-08-24
by Gabriele Mariotti

Original Post

Original - Posted on 2015-04-22
by Gabriele Mariotti



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Use the [Material components for android library][1] and the [`androidx.appcompat.app.AlertDialog`][2].
Just use something like:
new MaterialAlertDialogBuilder(context) .setTitle("Dialog") .setMessage("Lorem ipsum dolor ....") .setPositiveButton("Ok", /* listener = */ null) .setNegativeButton("Cancel", /* listener = */ null) .show();
Use a [Material Theme][3] and then [customize the shape][4] of your component using the **`shapeAppearanceOverlay`** attribute in your style.
Something like:
<!-- Alert Dialog --> <style name="MyThemeOverlayAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog"> <item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MyApp.Dialog.Rounded</item> </style>
Here you can define the rounded corners: <style name="ShapeAppearanceOverlay.MyApp.Dialog.Rounded" parent=""> <item name="cornerFamily">rounded</item> <item name="cornerSize">8dp</item> </style>
[![enter image description here][5]][5]

[1]: https://github.com/material-components/material-components-android [2]: https://developer.android.com/reference/androidx/appcompat/app/AlertDialog.html [3]: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#material-components-themes [4]: https://github.com/material-components/material-components-android/blob/master/docs/theming/Shape.md#customizing-component-shapes [5]: https://i.stack.imgur.com/j3Xem.png
**UPDATED ON Aug 2019 WITH The Material components for android library:**
With the new [Material components for android library][1] you can use the new [`androidx.appcompat.app.AlertDialog`][2].

Just use something like:
new MaterialAlertDialogBuilder(context) .setTitle("Dialog") .setMessage("Lorem ipsum dolor ....") .setPositiveButton("Ok", /* listener = */ null) .setNegativeButton("Cancel", /* listener = */ null) .show();
You can use in your theme something like:
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.MaterialComponents.Light"> ... <item name="materialAlertDialogTheme">@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog</item> </style>
You can also use the constructor:
new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_MaterialComponents_MaterialAlertDialog)

**WITH SUPPORT LIBRARY:**
With the new `AppCompat v22.1` you can use the new [android.support.v7.app.AlertDialog][3].
Just use a code like this:

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();
And use a style like this:
<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>
Otherwise you can define in your current theme:
<style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- your style --> <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item> </style>
and then in your code:
import android.support.v7.app.AlertDialog AlertDialog.Builder builder = new AlertDialog.Builder(this);
Here the AlertDialog on Kitkat: ![enter image description here][4]

[1]: https://github.com/material-components/material-components-android [2]: https://developer.android.com/reference/androidx/appcompat/app/AlertDialog.html [3]: http://developer.android.com/reference/android/support/v7/app/AlertDialog.html [4]: http://i.stack.imgur.com/YlRZO.png

        
Present in both answers; Present only in the new answer; Present only in the old answer;