【问题标题】:make my button style like the AlertDialog button Style [closed]使我的按钮样式像 AlertDialog 按钮样式 [关闭]
【发布时间】:2013-01-21 16:49:00
【问题描述】:

我想让我的按钮样式如下

我想用我的自定义视图来实现这些按钮,我的意思是不使用 AlertDialog

【问题讨论】:

    标签: android


    【解决方案1】:

    如果您更喜欢使用标准的 android 属性,请参阅我的回答 here

    简而言之,为您的按钮设置style="?android:attr/buttonBarButtonStyle" 并将它们放入具有style="?android:attr/buttonBarStyle"LinearLayout

    【讨论】:

    • 这是最正确的答案。属性 buttonBarButtonStyle 在全息主题中(不确定以前的)设置为无边框按钮样式,这是 OP 所追求的。 +1
    • 不幸的是,这需要 API 11。
    • 这看起来不像警报对话框。按钮上方或按钮中间没有分隔线
    • 我建议删除 android: 以使用 AppCompat 样式。不确定它们是否与?attr/buttonBarButtonStyle 不同,但也有?attr/buttonBarPositiveButtonStyle?attr/buttonBarNeutralButtonStyle?attr/buttonBarNegativeButtonStyle
    【解决方案2】:

    你可以用 xml 来做,像这样:

    把它放在drawable/border.xml中

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
       <solid android:color="#000000" />
       <stroke android:width="1dip" android:color="#333333"/>
    </shape>
    

    然后在你的布局文件中:

    <Button
        ...
        android:background="@drawable/border"
        android:textColor="#ffffff"
        android:textSize="13sp"
        ... />
    

    然后你可以设置你的宽度和高度让它看起来很棒! :)

    编辑: 我建议使用this 答案而不是认为,使用内置 Android 资源会更好。

    【讨论】:

    • 靠近图片但背景颜色不是黑色
    • 是的,但是您可以将背景颜色更改为您想要的任何颜色。只需在此处更改十六进制颜色:
    猜你喜欢
    • 2011-08-09
    • 1970-01-01
    • 2016-05-13
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多