如何解决Android Studio 无法更改 AlertDialog JAVA
我无法更改按钮的文本颜色,我尝试了在 stackoverflow 上找到的所有解决方案,但一无所获。
import androidx.appcompat.app.AlertDialog;
AlertDialog.Builder doubleDishConfirm = new AlertDialog.Builder(AggiungiPiattoAttivity.this,R.style.MyAlertDialogStyle);
doubleDishConfirm.setPositiveButton( ... )
doubleDishConfirm.setNegativeButton( ... )
doubleDishConfirm.show();
我的 MyAlertDialogStyle(在 themes.xml 中)是:
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<!--<item name="android:buttonBarNegativeButtonStyle">@android:color/black</item>
<item name="buttonBarNegativeButtonStyle">@android:color/black</item> -->
<!-- Used for the title and text -->
<item name="android:negativeButtonText">@android:color/black</item>
<item name="android:textColorPrimary">@android:color/black</item>
<!-- Used for the background -->
<item name="android:background">@android:color/white</item>
</style>
对我做过的其他测试有评论,我也试过 colorAceent 但没有。
它改变了文字“try1”和“try2”的背景颜色,但按钮的文字变得不可见。
解决方法
使用以下内容在您的 themes.xml 文件中设置 textColor 项:
<item name="android:textColor">@color/tab_background_light_pink</item>
如果还是不行,你可以
尝试在您的 onShowListener
上使用 AlertDialog
,然后调用 setTextColor
例如:
dialog.setOnShowListener( new OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
dialog.getButton(AlertDialog.(//id of your button)).setTextColor(//whichever color you want);
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。