gpt4 book ai didi

android - 全宽警报对话框按钮

转载 作者:行者123 更新时间:2023-12-05 03:28:20 24 4
gpt4 key购买 nike

我正在尝试让我的 AlertDialogs 看起来像这样,带有全宽按钮:

enter image description here

我正在关注 Google 的 documentation它说要使用这种风格:

 R.style.ThemeOverlay_MaterialComponents_MaterialAlertDialog_FullWidthButtons

但我无法访问该主题:

enter image description here

我在项目的 Gradle 文件中添加了适当的依赖项:

implementation 'com.google.android.material:material:1.5.0'

我觉得我只是遗漏了一些明显的东西。

最佳答案

库中缺少主题覆盖的实现。
您可以通过以下方式自行定义它:

声明全宽按钮样式,例如:

  <style name="Button.FullWidth" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:maxWidth">@null</item>
</style>

用全角按钮样式声明主题覆盖:

  <style name="ThemeOverlay.MaterialComponents.MaterialAlertDialog.FullWidthButtons">
<item name="materialAlertDialogButtonSpacerVisibility">2</item>
<item name="buttonBarPositiveButtonStyle">@style/Button.FullWidth</item>
<item name="buttonBarNegativeButtonStyle">@style/Button.FullWidth</item>
<item name="buttonBarNeutralButtonStyle">@style/Button.FullWidth</item>
</style>

enter image description here

关于android - 全宽警报对话框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71278132/

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