【问题标题】:Android custom button style: APi - < 21 and > 21 - attributesAndroid自定义按钮样式:APi - < 21 and > 21 - 属性
【发布时间】:2016-03-16 17:55:12
【问题描述】:

我想在styles.xml 中创建几个按钮样式。我想支持 API 19 及更高版本,所以我想为这两个 API 创建按钮样式。我在做什么:

我在stylex.xml 中创建了自定义样式:

<style name="AppTheme.ButtonGreen" parent="android:Widget.Holo.Button">
    <iten name="android:textColor">@color/accent</iten>
    <item name="android:background">@color/primary</item>
</style>

实际上颜色不会改变。您能帮我设置主题并提供一些基本属性,例如:背景颜色、文本颜色等,因为它们不起作用(只有字体颜色有效)。

我还在styles (v21).xml 中实现了 v21 的样式:

<style name="AppTheme.ButtonGreen" parent="android:Widget.Material.Button">
    <item name="android:textColor">@color/primary</item>
    <item name="android:background">@color/text_icons</item>
</style>

但这里我需要字体颜色、背景颜色、高度、字体大小等(只有字体颜色有效)。

通常我猜我做错了什么。你们能帮我为不同的 API 设置这些按钮的样式吗?

【问题讨论】:

    标签: android button themes


    【解决方案1】:

    请阅读这篇文章 https://www.androidcookbook.com/Recipe.seam?recipeId=3307

    StackOverflow 上的这个问题: How to create custom button in Android using XML Styles

    我认为第一个足以满足您的实际需求。

    如果您有任何问题,请随时提问。

    编辑:如果您仍然觉得卡住 - 也许最好创建一个图像并将其设置为 ImageButton

    http://angrytools.com/android/button/

    http://dabuttonfactory.com/

    或者尝试在较低的 API 中使用 Material Design 查找问题。这可能会有所帮助:how to use material design features in api lower than 21 in eclipse?

    【讨论】:

    • 我使用 v7.AppCompatButton
    • 这似乎是背景兼容性的问题。我已经编辑了帖子
    【解决方案2】:

    你必须使用背景而不是 backgroundtint

    【讨论】:

      猜你喜欢
      • 2015-05-15
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多