gpt4 book ai didi

Android 警报对话样式不适用于三星 6.0.1

转载 作者:行者123 更新时间:2023-11-29 16:53:50 26 4
gpt4 key购买 nike

我已经在 android 中为 android 对话框创建了样式,代码粘贴在下面。但是样式似乎不适用于 Android 6.0.1,三星手机。我也分享了两个屏幕截图。请帮我解决这个问题。

代码

<style name="GeneraButton1" parent="android:Widget.Button">
<item name="android:textColor">@color/colorPrimary</item><item name="android:fontFamily">sans-serif</item><item name="android:textSize">@dimen/key_text</item><item name="android:gravity">center</item><item name="android:background">@drawable/general_button1_selector</item>
</style>

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Used for the buttons --><item name="colorAccent">@color/white</item><!-- Used for the title and text --><item name="android:textColorPrimary">@color/colorPrimary</item><!-- Used for the title and text --><item name="android:textColor">@color/colorPrimary</item><!-- Used for the background --><item name="android:background">@color/white</item><item name="android:button">@style/GeneraButton</item><item name="android:actionButtonStyle">@style/GeneraButton</item>
</style>

Java代码

public void showAlertDialog(String title, String message, IAlertDialogueInterface handler, final View view, boolean setPositiveButton, int posBtnString, int negBtnStr) {
final IAlertDialogueInterface internalHandler;
if (handler == null) {
internalHandler = new AlertHandler();
} else {
internalHandler = handler;
}
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle);
alertDialogBuilder.setTitle(title);
alertDialogBuilder.setMessage(message);
alertDialogBuilder.setCancelable(false);
if (setPositiveButton) {
alertDialogBuilder.setPositiveButton(this.getString(posBtnString),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
alertDialog.dismiss();
internalHandler.onAlertButtonClick(arg1, view);
}
});
}
alertDialogBuilder.setNegativeButton(this.getString(negBtnStr), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
alertDialog.dismiss();
internalHandler.onAlertButtonClick(which, view);
}
});

alertDialog = alertDialogBuilder.create();

if (view != null) {
alertDialog.setView(view);
}
alertDialog.show();
}

MotoG4Plus(Android 7.0 屏幕截图) enter image description here

三星(Android 6.0.1 屏幕截图) enter image description here

最佳答案

如果来自代码,您必须这样做。如下所示:

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.YourAlertDialogStyle);
alertDialogBuilder.setTitle("title");
alertDialogBuilder.setMessage("message");
alertDialogBuilder.setCancelable(false);
final AlertDialog alertDialog = alertDialogBuilder.create();
//2. now setup to change color of the button
alertDialog.setOnShowListener(
new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
// like this set text color to all your buttons in dialog
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(COLOR_YOU_WANT);
}
});

编码愉快!!!

关于Android 警报对话样式不适用于三星 6.0.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45571895/

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