我無法找到解決方案!我正在嘗試遵循Android 2.1及更高版本。AlertDialog與列表項和自定義主題
我嘗試創建一個相當於AlertDialog一個自定義主題。
我發現在API v.11之前無法在AlertDialog上應用主題。我嘗試使用ContextThemeWrapper,但找不到定製按鈕的解決方案。
對於一個簡單的觀點,我創造我自己的對話與我自己的內容視圖。我做了我想要的主題。
但是,當我想要一個AlertDialog使用自定義主題和列表項,它是比較複雜的。我找不到在列表末尾添加按鈕的解決方案。因爲當列表太大時,按鈕在窗口外面。
我試着用: - 一個RelativeLayout的: *下面標題 *按鈕標題 *的ListView下面的ListView - 一個的LinearLayout垂直
任何人有一個想法?
我添加了result needed。
也許,我的最後一個,也是非常醜陋的想法是,用builder創建一個正常的AlertDialog,用findViewById查找每個視圖並應用所需的主題屬性......但是我必須看看自從Android以來,ID是否是常量2.1 ...
我的佈局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>
這應該是可以用RelativeLayout實現的,你可以發佈你試過的代碼嗎?也許我們可以幫助你實現它。 – FoamyGuy 2012-08-08 16:06:57
我只是添加了xml文件。 – JulienDR 2012-08-09 07:40:34
我找到了一個解決方案。 我是一個垂直的LinearLayout。 所有的觀點都與layout_weight 0 只是ListView控件是1 – JulienDR 2012-08-09 13:48:59