gpt4 book ai didi

java - 更改对话框中的按钮文本颜色

转载 作者:行者123 更新时间:2023-12-02 10:51:02 25 4
gpt4 key购买 nike

我正在尝试更改“Impostazioni”和“Chiudi”的颜色,但我不能,我该怎么办?

public class noNetworkConnection extends DialogFragment{

private String Titolo = "Errore";
private String Messaggio = "Sembra che tu non sia connesso a internet!";
private String Impostazioni = "Impostazioni";
private String Chiudi = "Chiudi";

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(Messaggio).setTitle(Titolo).setIcon(R.mipmap.ic_connection_error_nointernetconnecction)
.setPositiveButton(Impostazioni, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
}
})
.setNegativeButton(Chiudi, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.exit(0);
}
});
// Create the AlertDialog object and return it
return builder.create();
}

}

最佳答案

public void createDialog(final Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(Messaggio).setTitle(Titolo).setIcon(R.mipmap.ic_connection_error_nointernetconnecction)
.setPositiveButton(Impostazioni, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
}
})
.setNegativeButton(Chiudi, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.exit(0);
}
});

AlertDialog alert = builder.create();
alert.show();
Button negbutton = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
negbutton.setTextColor(getResources().getColor(R.color.green));
Button posButton = alert.getButton(DialogInterface.BUTTON_POSITIVE);
posButton.setTextColor(getResources().getColor(R.color.red));
}

关于java - 更改对话框中的按钮文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52182710/

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