1

解決策が見つかりません!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>
4

1 に答える 1

2

私は解決策を見つけました。私は垂直LinearLayoutです。すべてのビューのlayout_weightは0です。ListViewだけが1です。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/titleLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:padding="5dp" >

        <FrameLayout
            android:id="@+id/title_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:paddingRight="10dp" />

        <TextView
            android:id="@+id/title"
            style="@style/Dialog.Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_toLeftOf="@id/title_container" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/containerLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/dialog_header_divider" />
    </RelativeLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_weight="0"
        android:background="@color/grey_2" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/cancel_button"
            style="@style/Dialog.Button.Cancel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-1dp"
            android:layout_weight="1"
            android:text="@string/cancel" />

        <View
            android:id="@+id/buttonSeparator"
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_weight="0"
            android:background="@color/grey_2" />

        <Button
            android:id="@+id/ok_button"
            style="@style/Dialog.Button.Ok"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/ok" />
    </LinearLayout>

</LinearLayout>
于 2012-08-14T10:10:47.380 に答える