如何在 android 5 中更改默认对话框按钮文本颜色
How can I change default dialog button text color in android 5
我的应用程序中有很多警告对话框。这是默认布局,但我在对话框中添加了正负按钮。因此按钮获得默认文本颜色 Android 5(绿色)。我试图改变它但没有成功。知道如何更改文本颜色吗?
我的自定义对话框:
public class MyCustomDialog extends AlertDialog.Builder {
public MyCustomDialog(Context context,String title,String message) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View viewDialog = inflater.inflate(R.layout.dialog_simple, null, false);
TextView titleTextView = (TextView)viewDialog.findViewById(R.id.title);
titleTextView.setText(title);
TextView messageTextView = (TextView)viewDialog.findViewById(R.id.message);
messageTextView.setText(message);
this.setCancelable(false);
this.setView(viewDialog);
} }
正在创建对话框:
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
...
}
}).show();
那个 negativeButton 是一个默认的对话框按钮,默认的绿色来自 Android 5 Lollipop。
非常感谢
你可以先尝试创建AlertDialog
对象,然后用它来设置改变按钮的颜色然后显示。 (请注意,在 builder
对象上我们调用 create()
而不是调用 show()
来获取 AlertDialog
对象:
//1. create a dialog object 'dialog'
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
...
}
}).create();
//2. now setup to change color of the button
dialog.setOnShowListener( new OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(COLOR_I_WANT);
}
});
dialog.show()
您必须在 onShow()
上执行此操作并且不能在创建对话框后才获取该按钮的原因是该按钮尚未创建。
我将 AlertDialog.BUTTON_POSITIVE
更改为 AlertDialog.BUTTON_NEGATIVE
以反映您问题中的更改。尽管 "OK" 按钮是一个否定按钮很奇怪。一般是正键。
最简单的解决方案是:
dialog.show(); //Only after .show() was called
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(neededColor);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(neededColor);
按钮和其他文本的颜色也可以通过主题更改:
values-21/styles.xml
<style name="AppTheme" parent="...">
...
<item name="android:timePickerDialogTheme">@style/AlertDialogCustom</item>
<item name="android:datePickerDialogTheme">@style/AlertDialogCustom</item>
<item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
</style>
<style name="AlertDialogCustom" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">#00397F</item>
<item name="android:colorAccent">#0AAEEF</item>
</style>
结果:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorPrimary">#00397F</item>
<item name="android:textColorPrimary">#22397F</item>
<item name="android:colorAccent">#00397F</item>
<item name="colorPrimaryDark">#22397F</item>
</style>
按钮和其他文本的颜色也可以使用 appcompat 更改:
如果您想更改按钮文本颜色(正面、负面、中性),只需添加到您的自定义对话框样式:
<item name="colorAccent">@color/accent_color</item>
因此,您的对话框样式必须如下所示:
<style name="AlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">@android:color/black</item>
<item name="colorAccent">@color/topeka_accent</item>
</style>
作为旁注:
按钮的颜色(以及整个样式)也取决于当前主题,当您使用其中任何一种时,它们可能会有很大不同
android.app.AlertDialog.Builder builder = new AlertDialog.Builder()
或
android.support.v7.app.AlertDialog.Builder builder = new AlertDialog.Builder()
(最好用第二个)
这是一种使用样式的自然方法:
如果您的 AppTheme
继承自 Theme.MaterialComponents
,那么:
<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>
如果您的AppTheme
继承自Theme.AppCompat
:
<style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#f00</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#00f</item>
</style>
在 AppTheme
中使用您的 AlertDialogTheme
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
或在构造函数中
androidx.appcompat.app.AlertDialog.Builder(context, R.style.AlertDialogTheme)
或者如果您使用的是 MaterialAlertDialogBuilder,则使用
<item name="materialAlertDialogTheme">@style/AlertDialogTheme</item>
对我来说不同,我使用了按钮主题
<style name="ButtonLight_pink" parent="android:Widget.Button">
<item name="android:background">@drawable/light_pink_btn_default_holo_light</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textColor">@color/tab_background_light_pink</item>
</style>
因为 android:textColor
那里是白色的……我没有看到任何按钮文本(对话框按钮基本上也是按钮)。
我们去吧,改变它,修复它。
有两种方法可以更改对话框按钮的颜色。
基本方式
如果你只是想改变一个activity,在alertDialog.show();
之后写下面两行
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorPrimaryDark));
推荐
我建议在 styles.xml
中为 AlertDialog
添加一个主题,这样您就不必在每个 activity/dialog 调用中一次又一次地编写相同的代码。您可以只创建一个样式并将该主题应用到对话框中。因此,每当您想更改 AlertDialog 框的颜色时,只需在 styles.xml 中更改颜色,整个应用程序中的所有对话框都会更新。
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/colorPrimary</item>
</style>
并在 AlertDialog.Builder
中应用主题
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
在您应用的 theme/style 中,添加以下行:
<item name="android:buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="android:buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
<item name="android:buttonBarNeutralButtonStyle">@style/NeutralButtonStyle</item>
然后添加如下样式:
<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/red</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/red</item>
</style>
<style name="NeutralButtonStyle"
parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#00f</item>
</style>
使用此方法无需在 AlertDialog 构建器中设置主题。
方法如下:简单方法
// Initializing a new alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.message);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doAction();
}
});
builder.setNegativeButton(R.string.cancel, null);
// Create the alert dialog and change Buttons colour
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.red));
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.blue));
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(getResources().getColor(R.color.black));
}
});
dialog.show();
Kotlin 2020:非常简单的方法
dialog.show()
后使用:
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(requireContext(), R.color.yourColor))
使用styles.xml(值)
非常简单的解决方案,根据您的选择更改 colorPrimary,它将更改警报框按钮文本的颜色。
<style name="MyAlertDialogStyle" parent="android:Theme.Material.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">@android:color/white</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">@color/black</item>
<!-- Used for the background -->
<item name="android:background">#ffffff</item>
<item name="android:colorPrimary">@color/white</item>
<item name="android:colorAccent">@color/white</item>
<item name="android:windowEnterAnimation">@anim/bottom_left_enter</item>
</style>
替代(使用Java)
@SuppressLint("ResourceAsColor")
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
AlertDialog dialog = new AlertDialog.Builder(view.getContext(), R.style.MyAlertDialogStyle)
.setTitle("Royal Frolics")
.setIcon(R.mipmap.ic_launcher)
.setMessage(message)
.setPositiveButton("OK", (dialog1, which) -> {
//do nothing
result.confirm();
}).create();
Objects.requireNonNull(dialog.getWindow()).getAttributes().windowAnimations = R.style.MyAlertDialogStyle;
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(R.color.white);
return true;
}
我们可以创建扩展函数并在 dialog.show() 之后调用扩展函数来自定义 Alert Dialog 按钮颜色。
fun AlertDialog.makeButtonTextBlue() {
this.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(context, R.color.blue))
this.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(context, R.color.blue))
}
用法:
dialog.show()
dialog.makeButtonTextBlue()
快速简单的方法:
更改res/values/colors.xml中的colorAccent颜色,颜色以十六进制表示,例如#010613为黑色。
再见
This is a custom theme to change textColor of buttons on AlertDialog.
It works on my device - SamsungA70 - android 11
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<!--Support for other devices, I think so-->
<item name="android:textColor">@color/yourcolor</item>
<item name="colorButtonNormal">@color/yourcolor</item>
<item name="colorAccent">@color/yourcolor</item>
<!--only this code works on my device-->
<item name="buttonBarButtonStyle">@style/MyButtonStyle</item>
</style>
<!--only this code works on my device-->
<style name="MyButtonStyle" parent="Widget.AppCompat.Button.Borderless">
<item name="android:textColor">@color/yourcolor</item>
</style>
我的应用程序中有很多警告对话框。这是默认布局,但我在对话框中添加了正负按钮。因此按钮获得默认文本颜色 Android 5(绿色)。我试图改变它但没有成功。知道如何更改文本颜色吗?
我的自定义对话框:
public class MyCustomDialog extends AlertDialog.Builder {
public MyCustomDialog(Context context,String title,String message) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View viewDialog = inflater.inflate(R.layout.dialog_simple, null, false);
TextView titleTextView = (TextView)viewDialog.findViewById(R.id.title);
titleTextView.setText(title);
TextView messageTextView = (TextView)viewDialog.findViewById(R.id.message);
messageTextView.setText(message);
this.setCancelable(false);
this.setView(viewDialog);
} }
正在创建对话框:
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
...
}
}).show();
那个 negativeButton 是一个默认的对话框按钮,默认的绿色来自 Android 5 Lollipop。
非常感谢
你可以先尝试创建AlertDialog
对象,然后用它来设置改变按钮的颜色然后显示。 (请注意,在 builder
对象上我们调用 create()
而不是调用 show()
来获取 AlertDialog
对象:
//1. create a dialog object 'dialog'
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
...
}
}).create();
//2. now setup to change color of the button
dialog.setOnShowListener( new OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(COLOR_I_WANT);
}
});
dialog.show()
您必须在 onShow()
上执行此操作并且不能在创建对话框后才获取该按钮的原因是该按钮尚未创建。
我将 AlertDialog.BUTTON_POSITIVE
更改为 AlertDialog.BUTTON_NEGATIVE
以反映您问题中的更改。尽管 "OK" 按钮是一个否定按钮很奇怪。一般是正键。
最简单的解决方案是:
dialog.show(); //Only after .show() was called
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(neededColor);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(neededColor);
按钮和其他文本的颜色也可以通过主题更改:
values-21/styles.xml
<style name="AppTheme" parent="...">
...
<item name="android:timePickerDialogTheme">@style/AlertDialogCustom</item>
<item name="android:datePickerDialogTheme">@style/AlertDialogCustom</item>
<item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
</style>
<style name="AlertDialogCustom" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">#00397F</item>
<item name="android:colorAccent">#0AAEEF</item>
</style>
结果:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorPrimary">#00397F</item>
<item name="android:textColorPrimary">#22397F</item>
<item name="android:colorAccent">#00397F</item>
<item name="colorPrimaryDark">#22397F</item>
</style>
按钮和其他文本的颜色也可以使用 appcompat 更改:
如果您想更改按钮文本颜色(正面、负面、中性),只需添加到您的自定义对话框样式:
<item name="colorAccent">@color/accent_color</item>
因此,您的对话框样式必须如下所示:
<style name="AlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">@android:color/black</item>
<item name="colorAccent">@color/topeka_accent</item>
</style>
作为旁注:
按钮的颜色(以及整个样式)也取决于当前主题,当您使用其中任何一种时,它们可能会有很大不同
android.app.AlertDialog.Builder builder = new AlertDialog.Builder()
或
android.support.v7.app.AlertDialog.Builder builder = new AlertDialog.Builder()
(最好用第二个)
这是一种使用样式的自然方法:
如果您的 AppTheme
继承自 Theme.MaterialComponents
,那么:
<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>
如果您的AppTheme
继承自Theme.AppCompat
:
<style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#f00</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#00f</item>
</style>
在 AppTheme
AlertDialogTheme
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
或在构造函数中
androidx.appcompat.app.AlertDialog.Builder(context, R.style.AlertDialogTheme)
或者如果您使用的是 MaterialAlertDialogBuilder,则使用
<item name="materialAlertDialogTheme">@style/AlertDialogTheme</item>
对我来说不同,我使用了按钮主题
<style name="ButtonLight_pink" parent="android:Widget.Button">
<item name="android:background">@drawable/light_pink_btn_default_holo_light</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textColor">@color/tab_background_light_pink</item>
</style>
因为 android:textColor
那里是白色的……我没有看到任何按钮文本(对话框按钮基本上也是按钮)。
我们去吧,改变它,修复它。
有两种方法可以更改对话框按钮的颜色。
基本方式
如果你只是想改变一个activity,在alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorPrimaryDark));
推荐
我建议在 styles.xml
中为 AlertDialog
添加一个主题,这样您就不必在每个 activity/dialog 调用中一次又一次地编写相同的代码。您可以只创建一个样式并将该主题应用到对话框中。因此,每当您想更改 AlertDialog 框的颜色时,只需在 styles.xml 中更改颜色,整个应用程序中的所有对话框都会更新。
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/colorPrimary</item>
</style>
并在 AlertDialog.Builder
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
在您应用的 theme/style 中,添加以下行:
<item name="android:buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item> <item name="android:buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item> <item name="android:buttonBarNeutralButtonStyle">@style/NeutralButtonStyle</item>
然后添加如下样式:
<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog"> <item name="android:textColor">@color/red</item> </style> <style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog"> <item name="android:textColor">@color/red</item> </style> <style name="NeutralButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog"> <item name="android:textColor">#00f</item> </style>
使用此方法无需在 AlertDialog 构建器中设置主题。
方法如下:简单方法
// Initializing a new alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.message);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doAction();
}
});
builder.setNegativeButton(R.string.cancel, null);
// Create the alert dialog and change Buttons colour
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.red));
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.blue));
//dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(getResources().getColor(R.color.black));
}
});
dialog.show();
Kotlin 2020:非常简单的方法
dialog.show()
后使用:
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(requireContext(), R.color.yourColor))
使用styles.xml(值)
非常简单的解决方案,根据您的选择更改 colorPrimary,它将更改警报框按钮文本的颜色。
<style name="MyAlertDialogStyle" parent="android:Theme.Material.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">@android:color/white</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">@color/black</item>
<!-- Used for the background -->
<item name="android:background">#ffffff</item>
<item name="android:colorPrimary">@color/white</item>
<item name="android:colorAccent">@color/white</item>
<item name="android:windowEnterAnimation">@anim/bottom_left_enter</item>
</style>
替代(使用Java)
@SuppressLint("ResourceAsColor")
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
AlertDialog dialog = new AlertDialog.Builder(view.getContext(), R.style.MyAlertDialogStyle)
.setTitle("Royal Frolics")
.setIcon(R.mipmap.ic_launcher)
.setMessage(message)
.setPositiveButton("OK", (dialog1, which) -> {
//do nothing
result.confirm();
}).create();
Objects.requireNonNull(dialog.getWindow()).getAttributes().windowAnimations = R.style.MyAlertDialogStyle;
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(R.color.white);
return true;
}
我们可以创建扩展函数并在 dialog.show() 之后调用扩展函数来自定义 Alert Dialog 按钮颜色。
fun AlertDialog.makeButtonTextBlue() {
this.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(context, R.color.blue))
this.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(context, R.color.blue))
}
用法:
dialog.show()
dialog.makeButtonTextBlue()
快速简单的方法: 更改res/values/colors.xml中的colorAccent颜色,颜色以十六进制表示,例如#010613为黑色。 再见
This is a custom theme to change textColor of buttons on AlertDialog. It works on my device - SamsungA70 - android 11
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<!--Support for other devices, I think so-->
<item name="android:textColor">@color/yourcolor</item>
<item name="colorButtonNormal">@color/yourcolor</item>
<item name="colorAccent">@color/yourcolor</item>
<!--only this code works on my device-->
<item name="buttonBarButtonStyle">@style/MyButtonStyle</item>
</style>
<!--only this code works on my device-->
<style name="MyButtonStyle" parent="Widget.AppCompat.Button.Borderless">
<item name="android:textColor">@color/yourcolor</item>
</style>