我目前正在創建一個自定義對話框(alertdialog不夠靈活,我的需要)。我希望它看起來像一個AlertDialog,具有良好的AlertDialog頭(見下圖)。自定義對話框,看起來像一個AlertDialog
另外我在我的自定義對話框中有一個listview,我希望它看起來像AlertDialog的列表視圖。我怎麼能這樣做?
到目前爲止,我在attr中找到了alertDialogTheme和alertDialogStyle。類,但我不知道如何使用它。
它應該是什麼樣子使用自定義對話框:
是什麼樣子(黑色背景,錯報頭):
我的佈局是非常基本的,看起來像這樣:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
listview包含使用此佈局的項目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/icon_noimage" />
<TextView
android:id="@+id/text"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="18dp" />
</LinearLayout>
有什麼想法?
--->解決方法使用alerdialog與自定義視圖,但現在我得到了下面的問題與一些差距:利用典型AlertDialog
標題/頭
嗯好頭應該工作。但我提供的列表是動態創建的。我不確定你的意思是重新創建列表視圖項目。你能更精確地解釋一下如何讓自定義listview的alertdialog listview看起來像customLayout一樣嗎? – masi 2012-02-06 23:49:32
據我所知,沒有可以繼承的默認主題或類似的東西。您只需手動佈置項目並設置邊距和填充以及字體大小以使其與您想要的匹配。僅供參考,您可以在創建'AlertDialog'之前動態更改'AlertDialog'列表中的項目。爲什麼這不適合你? – 2012-02-07 16:36:07
好吧,它現在就像你現在所說的那樣工作,除了我還有一個小小的錯誤,我用一個問題的示例圖像編輯了初始問題:我無法擺脫那些空白! – masi 2012-02-07 18:58:16