Skip to content Skip to sidebar Skip to footer

How Do I Create A Two-color Dialog Like This?

I'm looking to create a Dialog styled like the below, but I'm a little stuck. It has rounded corners and two different background colors. It will contain multiple Textviews in a ve

Solution 1:

You can create custom layout and inflate that layout using setContentView() for dialog;

        custom dialog;

        finalDialogdialog=newDialog(context);

        dialog.setContentView(R.layout.custom);

        dialog.setTitle("Title...");

        // set the custom dialog components - text, image and buttonTextViewtext= (TextView) dialog.findViewById(R.id.text);
        text.setText("Android custom dialog example!");
        ImageViewimage= (ImageView) dialog.findViewById(R.id.image);
        image.setImageResource(R.drawable.ic_launcher);

        ButtondialogButton= (Button) dialog.findViewById(R.id.dialogButtonOK);
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(newOnClickListener() {
            @OverridepublicvoidonClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();

Layout for this:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="match_parent"android:layout_height="70"android:text="White Text Goes Here"android:gravity="center"android:textColor="#fff"android:layout_marginRight="5dp"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:textSize="18dp"android:background="@drawable/custom_drwable"/><TextViewandroid:layout_marginRight="5dp"android:layout_marginLeft="5dp"android:layout_width="match_parent"android:layout_height="120"android:text="Red Text Goes Here"android:gravity="center"android:textColor="#F2122B"android:textSize="18dp"android:background="#fff"/></LinearLayout>

drawable for same:

<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"><solidandroid:color="#F2122B"/><cornersandroid:topLeftRadius="4dp"android:topRightRadius="4dp"/></shape>

Post a Comment for "How Do I Create A Two-color Dialog Like This?"