FragmentDialog中的按钮样式

时间:2013-10-21 17:50:41

标签: android android-fragments android-dialog android-styles

我创建了一个简单的评级对话框,扩展了FragmentDialog。结果如下:

enter image description here

但我希望获得一个样式,就像在android

中使用的典型对话框中使用的按钮一样

enter image description here

如何获得此结果?

2 个答案:

答案 0 :(得分:1)

 <View
        android:id="@+id/divider"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_above="@+id/submit_layout"
        android:layout_alignParentBottom="false"
        android:background="?android:attr/listDivider" />

    <LinearLayout
        android:id="@+id/submit_layout"
        style="@style/ButtonBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:descendantFocusability="beforeDescendants"
        android:gravity="center_vertical"
        android:minHeight="48dp"
        android:orientation="vertical" >

        <Button
            android:id="@+id/reload_btn"
            style="@style/ButtonBarButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/selectable_item_background"
            android:minHeight="48dp"
            android:text="Submit" />
    </LinearLayout>

和“selectable_item_background.xml”:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/item_pressed" android:state_pressed="true" />
    <item android:drawable="@drawable/item_focused" android:state_focused="true" />
    <item android:drawable="@drawable/item_focused" android:state_selected="true" />
    <item android:drawable="@android:color/transparent" />
</selector>

答案 1 :(得分:1)

向DialogFragment的方法setStyle(int,int)提供STYLE_NO_FRAME并使用TextViews代替自定义布局中的两个按钮应该可以解决问题。