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

AlertDialogs setCustomTitle not working with android.support.v7.app.AlertDialog

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

但预期的 AlertDialog 低于

正在创建警报对话框

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))

有自定义标题的视图。