gpt4 book ai didi

android - 使用带有警报对话框的最新 Material 概述按钮

转载 作者:行者123 更新时间:2023-12-02 02:48:03 25 4
gpt4 key购买 nike

我想使用带有默认警报对话框的新 Material 轮廓按钮。

我在 中创建了样式样式.xml 如下

<style name="OutlinedButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="strokeColor">@color/colorAccent</item>
<item name="strokeWidth">2dp</item>
</style>

<style name="MaterialDialogStyle" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="android:textColorPrimary">@color/colorAccent</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimary">@color/colorAccent</item>
<item name="buttonStyle">@style/OutlinedButton</item>
</style>

我正在使用新的 Material Components 主题来设置 Yes 和 No 按钮的样式。

现在我通过将其设置为 AlertDialog 构建器在我的代码中使用上述样式。
AlertDialog.Builder builder = new AlertDialog.Builder(ProductListActivity.this, R.style.MaterialDialogStyle);

但输出如下
enter image description here

有没有办法使用带有默认警报对话框的最新 Material 概述按钮?如果有任何区别,我正在使用设计支持库中的 Material 组件。

最佳答案

由于您使用的是 Material 主题,因此您可以使用:

      new MaterialAlertDialogBuilder(MainActivity.this, R.style.MyMaterialAlertDialog)
.setTitle("Clear cart")
.setMessage("Pressing back...")
.setPositiveButton("YES", null)
.setNegativeButton("NO", /* listener = */ null)
.show();

然后定义样式:
  <style name="MyMaterialAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">@style/OutlinedButton</item>
<item name="buttonBarNegativeButtonStyle">@style/OutlinedButton</item>
</style>

<style name="OutlinedButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="strokeColor">@color/colorAccent</item>
<item name="strokeWidth">2dp</item>
</style>

enter image description here

关于android - 使用带有警报对话框的最新 Material 概述按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53429068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com