解決策が見つかりません!Android2.1以降に準拠しようとしています。
カスタムテーマでAlertDialogに相当するものを作成しようとしています。
API v。11より前のAlertDialogにテーマを適用することはできないことがわかりました。また、ContextThemeWrapperを使用しようとしましたが、ボタンをカスタマイズするための解決策が見つかりません。
単純なビューの場合、独自のコンテンツビューを使用して独自のダイアログを作成します。そして、私はテーマでやりたいことをします。
ただし、カスタムテーマとリストアイテムを含むAlertDialogが必要な場合は、より複雑になります。リストの最後にボタンを追加するための解決策が見つかりません。リストが大きすぎると、ボタンがウィンドウの外側にあるためです。
試してみました:-RelativeLayout:* Title * ListView under title * Buttons under ListView-LinearLayout vertical
誰かアイデアがありますか?
必要な結果を追加します。
たぶん、私の最後の、そして非常に醜い考えは、ビルダーで通常のAlertDialogを作成し、findViewByIdで各ビューを見つけて、目的のテーマ属性を適用することです...しかし、Android2.1以降IDが一定であるかどうかを確認する必要があります...
私のレイアウト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>