I can’t find the solution! I am trying to be compliant with Android 2.1 and later.
I try to create an equivalent to AlertDialog with a a custom theme.
I found that it is not possible to apply a theme on an AlertDialog before API v. 11. And I try to use ContextThemeWrapper, but I can’t find a solution to customize the buttons.
For a simple view, I create my own Dialog with my own content view. And I do what I want with the theme.
But, when I want an AlertDialog with a custom theme AND a list item, it is more complicated. I can’t find a solution to add button at the end of the list. Because when the list is too big, the buttons are outside the window.
I tried with :
– a RelativeLayout :
* Title
* ListView below title
* Buttons below ListView
– A LinearLayout vertical
Anyone has an idea ?
I add the result needed.
Maybe, my last, and very ugly idea, is to create a normal AlertDialog with a builder, find each view with findViewById and apply the desired theme attributes… but I have to see if the ids are constant since Android 2.1 …
My layout xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bw="http://schemas.android.com/apk/res-auto/com.levelup.beautifulwidgets"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/ab_background"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textColor="@color/grey_1"
android:textSize="24dp" />
<FrameLayout
android:id="@+id/title_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:paddingRight="10dp" />
<ListView
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title" />
<LinearLayout
android:id="@+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@id/container"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<Button
android:id="@+id/cancel_button"
style="@style/DialogButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-1dp"
android:layout_weight="1"
android:text="@string/cancel" />
<Button
android:id="@+id/ok_button"
style="@style/DialogButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
</LinearLayout>
</RelativeLayout>
I found a solution. I an vertical LinearLayout. All the view are with a layout_weight to 0. Just the ListView is 1.