作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想自定义 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>
CustomAlertDialogBuilder
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/
我是一名优秀的程序员,十分优秀!