Reputation: 3966
This seems to be a very simple problem but I have searched and I can't find any solution. I have a Dialog with content, like this one:
And I want to change the color of "Enter Password", the Dialog's title. How can I do it?
Upvotes: 0
Views: 6205
Reputation: 338
There seems to be a very simple answer:
String chars = getResources().getString(R.string.playerDialogTitle);
SpannableString str = new SpannableString(chars);
str.setSpan(new ForegroundColorSpan(Color.WHITE), 0, chars.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
AlertDialog.Builder builder = new AlertDialog.Builder(PlayerActivity.this);
builder.setTitle(str)
Upvotes: 6
Reputation: 3966
The method setCustomTitle(View customTitleView)
allows you to do that. You need to create a layout to set in this, and in that layout simply set to the TextView the style you want.
This method belongs to AlertDialog.Builder:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customTitleView = inflater.inflate(R.layout.custom_title_view, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCustomTitle(customTitleView);
Upvotes: 2