Customize Alert Dialog on Android

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

Thank.

+3
source share
2 answers

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


as in this example, the layout defined in the file for warning. You can set your own style for the warning dialog box.

+6
source

You can create your own layout in the XML view in the same way as for 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)in 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);

, .

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

+6

Source: https://habr.com/ru/post/1787451/


All Articles