【发布时间】:2017-08-15 23:33:54
【问题描述】:
我正在尝试为我的应用主题设置样式。 我正在使用 Android 7、AppCompat v24 和 Xamarin,但我认为后者不会影响我面临的问题。
我正在尝试使用本指南设置按钮样式: http://www.materialdoc.com/raised-button/
这是我的主题:
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="alertDialogTheme">@style/MyAlertDialog</item>
按钮样式:
<style name="MyButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">@color/primaryDark</item>
<item name="colorButtonNormal">@color/primary</item>
这是我的按钮:
<Button
android:id="@+id/buttonStart"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="Start"
android:padding="20dp"
android:textSize="18dp"
android:theme="@style/MyButton"/>
问题是在链接中,当按钮被设置样式时,文本颜色是白色的,而在我的项目中它仍然是黑色的。
如果我将android:textColor="@color/white" 添加到我的按钮,我会得到白色文本,但它不再对启用-禁用状态做出反应。按钮在两种状态下看起来都一样,并且文本颜色不会像示例中那样变为浅灰色。
我想得到与链接中描述的结果相同的结果。我错过了什么?谢谢!
【问题讨论】:
-
尝试使用
style=而不是android:theme=。可能很难找到使用哪个,但您可能会找到 here。另外,为了完整起见,请发布 MyButton 样式声明。 -
对不起,我添加了按钮样式。使用 style 而不是 android:theme 会使按钮忽略背景颜色(默认变为灰色)。它还将文本字体更改为小写。
-
尝试将
MyButton的父级更改为Widget.AppCompat.Button.Colored并在那里添加textColor white。 -
按钮上的黑色文本与以前相同!
标签: android button material-design android-appcompat