3

I have a custom DialogPreference that just contains a date picker. Everything works fine EXCEPT the dialog has a huge border and title around it as can be seen below.

enter image description here

I would like the dialog to just be the date picker:

enter image description here

I've figured out how to remove the title by setting the window title to null, but the massive border still exists.

My custom layout:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <DatePicker 
        android:id="@+id/birthdayPicker"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center_horizontal"
        android:calendarViewShown="false"/>

</LinearLayout>

I've tried setting the linear layouts width/height to wrap_content, setting negative margins, and a host of other hackey solutions but nothing seems to be working.

The only luck I've had so far is overriding onShow and programmatically setting the windows size to some arbitrary amount - like a width of 300dp. This is obviously super duper hackey and I'd prefer a more elegant solution. Any help would be much appreciated guys!

3
  • Why does your LinearLayout has match_parent for both width and height? Jan 12, 2015 at 17:05
  • maybe a wrap_content for your LinearLayout layout_width?
    – Nasir
    Jan 12, 2015 at 17:06
  • I'm currently finding the same problem, with a TimePicker instead of a DatePicker. Did you ever find a solution to this? Would you mind sharing the onShow hack?
    – Alex
    Oct 4, 2020 at 13:07

1 Answer 1

0
<?xml version="1.0" encoding="utf-8"?>

Your LinearLayout should not be match_parent but wrap_content eg the DatePicker's dimensions.

Try:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <DatePicker 
        android:id="@+id/birthdayPicker"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center_horizontal"
        android:calendarViewShown="false"/>

</LinearLayout>
1
  • 1
    Yeah I tried that with no luck - match_parent vs wrap_content seems to make no difference. Jan 12, 2015 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.