0

I am styling my AlertDialog. I have successfully been able to style the background (see its blue) and the single choice items (see they are white with orange text).

Is it possible to style the AlertDialog title background, the footer submit button and footer background? See the image below for these areas highlighted in red. Is it possible to make the AlertDialog to have rounded rectangle corners?

As you can see I can set the title label background colour to blue but not the whole title background?

enter image description here

Implementation:

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(mActivity, R.style.AlertDialogCustom));
builder.setTitle("Select");

ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
        getActivity(), R.layout.choices, choices);
builder.setSingleChoiceItems(adapter, -1, myOnClickListener);


// Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">#00FF00</item>
        <item name="android:textSize">10sp</item>
        <item name="android:background">#0000ff</item>
        <item name="android:fontFamily">fonts/myCustomFont.ttf</item>
    </style>
</resources>


// choices.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:fontFamily="fonts/myCustomFont.ttf"
    android:textColor="@color/theme_orange"
    android:gravity="center_vertical"
    android:ellipsize="marquee"
    android:text="Text"
    android:background="#fff"
    android:paddingLeft="16dip"
    android:paddingRight="7dip"/>
sazr
  • 24,984
  • 66
  • 194
  • 362

2 Answers2

0

You can use a custom layout (xml file) instead of this and add all your requirements there. Then set that view to your dialog as:

builder.setView(R.layout.custom_view);

Also don't forget to remove the title as mentioned here.

Community
  • 1
  • 1
Saeed Jassani
  • 1,079
  • 2
  • 11
  • 27
0

In this link I showed how to Style AlertDialog Submit Button and Title. It also shows how to customize the AletDialog. For example, how to change divider colro and etc. Please visit this link:

https://stackoverflow.com/a/33439849/5475941.

I hope it helps.

Community
  • 1
  • 1
Mohammad
  • 6,024
  • 3
  • 22
  • 30