java - Activity 的 AlertDialog 样式按钮

标签 java android

我有一个底部有保存和取消按钮的 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/

相关文章:

java - Wicket 口 6 中的异常处理进入反馈面板

java - 如何配置Spring TestRestTemplate

java - 代理的Weblogic设置

android - 在应用程序启动时突然收到 Firebase java.lang.IllegalAccessError

java命令提示符编译错误

android - 通过 Intent 而不是构造函数传递数据

java - 如何保存变量值?

android - 验证在哪个 Activity 中附加了 fragment

android - 当我们更改三星设备中的设备字体样式时如何防止 TextView 字体更改

java - Jetty 配置 - java.lang.ClassNotFoundException : org. eclipse.jetty.server.ProxyConnectionFactory