How can I change the background color for an alertbox\'s title bar?
AlertDialog.Builder alert=new AlertDialog.Builder(getParent());
alert.setTitle(\"sample\");
a
From the answer @CornflakesDK and @ice spirit, I thought you can use the current AlertDialog.Builder
implementation to do the custom dialog and make it easy to maintain.
CustomDialogBuilder.java
public class CustomDialogBuilder extends AlertDialog.Builder {
private View view;
public CustomDialogBuilder(Context context) {
super(context);
view = LayoutInflater.from(getContext()).inflate(R.layout.custom_dialog_title, null);
setCustomTitle(view);
}
@Override
public Builder setTitle(int titleId) {
TextView titleTextView = view.findViewById(R.id.exemptionSubHeading4);
titleTextView.setText(getContext().getString(titleId));
return this;
}
@Override
public Builder setTitle(CharSequence title) {
TextView titleTextView = view.findViewById(R.id.exemptionSubHeading4);
titleTextView.setText(title);
return this;
}
}
custom_dialog.xml
Inside your activity code,
new CustomDialogBuilder(MyActivity.this)
.setTitle(R.string.actions)
.setItems(R.array.items_actions, (dialog, which) -> {
// handle items
}).create().show();
Then, you can have styling inside the DialogBuilder and also utilize the functions of the AlertDialog.Builder.