我有一个底部有保存和取消按钮的 Activity 。
在 AlertDialog 中,按钮显示在某种样式化的容器 View 中。
我怎样才能让我的 Activity 中的按钮具有相同的外观?具体来说,我如何在 AlertDialog 中应用按钮容器 View 的样式来在包含按钮的 Activity 中说出 LinearLayout?
谢谢
最佳答案
给出了解决方案elsewhere那个工作。简而言之,您只需在 xml 中使用 style
属性即可实现此目的。例如,style="?android:attr/buttonBarStyle"
和 style="?android:attr/buttonBarButtonStyle"
将完成这项工作(对于 API 11+)。下面是两个按钮水平放在一起的示例。
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:paddingTop="0dip" >
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text= "Ok" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
唯一剩下的是 alertDialog
中的按钮正上方有一条水平线,上面的代码不会创建它。如果你想要那条水平线,它应该在 LinearLayout
上方的 xml 中手动添加。这将为您提供水平线:
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginBottom="0dp"
android:background="?android:attr/dividerVertical" />
关于java - Activity 的 AlertDialog 样式按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5735423/