6

I want to show text in dark color on a light background on alert dialog. But I can't figure out how to do this. Please help me.

Thanks.

1

2 Answers 2

7

You can create your own layout in an XML View just like you would for an Activity:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_root" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="10dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textColor="#FFF" /> </LinearLayout> 

Then you can use this View in the Dialog by calling setContentView(View) on the Dialog:

Context mContext = getApplicationContext(); Dialog dialog = new Dialog(mContext); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Custom Dialog"); TextView text = (TextView) dialog.findViewById(R.id.text); text.setText("Hello, this is a custom dialog!"); ImageView image = (ImageView) dialog.findViewById(R.id.image); image.setImageResource(R.drawable.android); 

As the example shows, you'll have to set some of the values after you declare the content view.

Example provided from http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Sign up to request clarification or add additional context in comments.

1 Comment

According to google's Documentation you should avoid instantiating the Dialog class directly. Better to use DialogFragment
6

see this example,It will help you:http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application


as in this example layout defined in file for alert dialog.You can set your style for alert dialog.

1 Comment

Thats a custom dialog. Can't we modify the alert dialog itself?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.