[英]Changing color for positive button of alert dialog in android studio
I am trying to change my positive button of the alert dialog.我正在尝试更改警报对话框的肯定按钮。 Can someone please help me?
有人可以帮帮我吗?
This is what I have tried so far in my theme.xml from reading other people's answer:这是我到目前为止在我的 theme.xml 中通过阅读其他人的答案所尝试的:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyFirstTest" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/yellow_200</item>
<item name="colorPrimaryVariant">@color/yellow_500</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:positiveButtonText">#00f</item>
</style>
<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert">
<item name="buttonBarPositiveButtonStyle">@style/Alert.Button.Positive</item>
</style>
<style name="Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#00f</item>
<item name="android:textSize">14sp</item>
<item name="android:textAllCaps">false</item>
</style>
</resources>
I am trying to change the positive button color to blue (#00f), but it kept on showing my primary color (yellow_200).我试图将正按钮颜色更改为蓝色 (#00f),但它一直显示我的原色 (yellow_200)。 I honestly do not know how to customize this theme: Theme.MaterialComponents.Light.NoActionBar Is there a website that guides what is included in this theme and how to customize it?
老实说,我不知道如何自定义此主题: Theme.MaterialComponents.Light.NoActionBar 是否有网站可以指导此主题中包含的内容以及如何自定义?
Thank you!谢谢!
There is some things that are currently wrong.目前有些事情是错误的。 You need to update your styles as follows to change the text color
您需要按如下方式更新样式以更改文本颜色
<style name="AlertDialogTheme" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#f00</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#00f</item>
</style>
You can find more information regarding material components and their theming on their website as follows您可以在其网站上找到有关材料组件及其主题的更多信息,如下所示
https://material.io/components/dialogs/android#theming-dialogs https://material.io/components/dialogs/android#theming-dialogs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.