0

I'm trying to change properties of my AlertDialog inside of my game, currently I'm building it with this way:

private static final int DIALOG_INFO = 1;

private Dialog dialog;  

@Override  
protected Dialog onCreateDialog(int id)  
{  
    AlertDialog.Builder builder = new AlertDialog.Builder(this);  

    switch (id)   
    {       
        case DIALOG_INFO:  

            builder.setTitle("Game Information - Diego 1.0.1");  
            builder.setIcon(R.drawable.icon);  
            builder.setMessage("Test there \n\n");  
            builder.setCancelable(true);  

            dialog = builder.create();  
            dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);                
            break;  
    }   
    return dialog;  
}

And if player clicked certain button, I'm showing this dialog with this way:

showDialog(DIALOG_INFO); 

Everything works, but I decided to change look of font used in this dialog, with this way:

TextView textView = ((TextView) dialog.findViewById(android.R.id.message));
textView.setTextColor(Color.LTGRAY);
textView.setTextSize(13);
textView.setGravity(Gravity.CENTER);

But code works only, if I put this code after showDialog(DIALOG_INFO); which means I have to create new object (TextView textView = ...) everytime I'm showing dialog, and my question is, can't I do it only once while creating dialog?

Thanks in advance.

Matthewek
  • 1,519
  • 2
  • 22
  • 42

1 Answers1

1

You can set your own contentView for AlertDialog:

.....
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = (ViewGroup) inflater.inflate(R.layout.YOUR_DIALOG_LAYOUT, null);
builder.setView(rootView);
.....

And markup your dialog layout in xml.

Vyacheslav Shylkin
  • 9,741
  • 5
  • 39
  • 34