gpt4 book ai didi

android - AlertDialogs setCustomTitle 不适用于 android.support.v7.app.AlertDialog

转载 作者:行者123 更新时间:2023-11-30 01:17:39 25 4
gpt4 key购买 nike

我想自定义 V7 AlertDialog 的 TITLE 颜色。 SetCustomTitle() 似乎无法与 android.support.v7.app.AlertDialog 一起使用。我可以看到如下所示的空白 TITLE

enter image description here

但预期的 AlertDialog 在下面

enter image description here

创建警报对话框

private void createDialog() {
ContextThemeWrapper ctw = new ContextThemeWrapper( mContext, R.style.TooltipTheme);
AlertDialog.Builder builder = new CustomAlertDialogBuilder(ctw);
builder.setTitle(mTitle);
builder.setMessage(mMsg);
builder.setPositiveButton(mOkButton,null);

AlertDialog alert11 = builder.create();
alert11.show();
Button positiveButton = alert11.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(mContext.getResources().getColor(R.color.BNPP_Color_Palette_PrimaryBtn));
}

style.xml

  <style name="TooltipTheme" parent="Theme.AppCompat.Dialog.Alert"></style>

CustomAlertDialogBu​​ilder

public class CustomAlertDialogBuilder  extends AlertDialog.Builder {

private final Context mContext;
private TextView mTitle;
private ImageView mIcon;
private TextView mMessage;

public CustomAlertDialogBuilder(Context context) {
super(context);
mContext = context;

View customTitle = View.inflate(mContext, R.layout.alert_dialog_title, null);
mTitle = (TextView) customTitle.findViewById(R.id.alertTitle);
mIcon = (ImageView) customTitle.findViewById(R.id.icon);
setCustomTitle(customTitle);

View customMessage = View.inflate(mContext, R.layout.alert_dialog_message, null);
mMessage = (TextView) customMessage.findViewById(R.id.message);
setView(customMessage);


}

@NonNull
@Override
public AlertDialog.Builder setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener) {
return super.setPositiveButton(text, listener);
}

@NonNull
@Override
public AlertDialog.Builder setPositiveButton(int textId, DialogInterface.OnClickListener listener) {
return super.setPositiveButton(textId, listener);
}

@Override
public CustomAlertDialogBuilder setTitle(int textResId) {
mTitle.setText(textResId);
return this;
}
@Override
public CustomAlertDialogBuilder setTitle(CharSequence text) {
mTitle.setText(text);
return this;
}

@Override
public CustomAlertDialogBuilder setMessage(int textResId) {
mMessage.setText(textResId);
return this;
}

@Override
public CustomAlertDialogBuilder setMessage(CharSequence text) {
mMessage.setText(text);
return this;
}

@Override
public CustomAlertDialogBuilder setIcon(int drawableResId) {
mIcon.setImageResource(drawableResId);
return this;
}

@Override
public CustomAlertDialogBuilder setIcon(Drawable icon) {
mIcon.setImageDrawable(icon);
return this;
}

}

最佳答案

您可以使用

禁用标准标题
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

通过

builder.setView(inflater.inflate(R.layout.dialog_signin, null))

拥有自定义标题的 View 。

关于android - AlertDialogs setCustomTitle 不适用于 android.support.v7.app.AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594069/

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