Android自定义按钮样式:APi-<21和>21-属性

Android custom button style: APi - < 21 and > 21 - attributes

我想在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 设置这些按钮的样式吗?

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

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

我觉得第一个就可以满足你的实际需求了。

如有疑问,欢迎随时提问。

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

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

http://dabuttonfactory.com/

或者尝试在较低的 API 中使用 Material 设计查找问题。这可能会有所帮助:

你必须使用 background 而不是 backgroundtint