有没有办法仅使用styles.xml设置本机AlertDialog角半径,而无需额外的代码?

时间:2019-05-09 07:33:21

标签: android alertdialog

我想知道有什么方法可以实现吗?问题仅在于styles.xml代码的修改,而不是通过编程自定义布局来进行自定义对话框。

1 个答案:

答案 0 :(得分:0)

您可以使用customize the shape shapeAppearanceOverlay 属性AlertDialog中的Material Theme组件。

类似的东西:

  <!-- Alert Dialog -->
  <style name="MyThemeOverlayAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MyApp.Dialog.Rounded</item>
  </style>

  <style name="ShapeAppearanceOverlay.MyApp.Dialog.Rounded" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">8dp</item>
  </style>

enter image description here

它需要材料组件库的1.1.0版本。