我可以通过在对象内设置按钮文本外观来更改按钮文本外观,如下所示:
<Button
android:id="@+id/login_btn_bypass"
android:textSize="15dp"
android:textColor="#878787"
android:textStyle="bold" />
但在样式中使用 textAppearance 时则不然
// in layout xml
<Button
android:id="@+id/login_btn_login"
android:textAppearance="@style/login_button_text_appearance" />
// in style definition
<style name="login_button_text_appearance">
<item name="android:textSize">15dp</item>
<item name="android:textColor">#a7a7a7</item>
<item name="android:textStyle">bold</item>
</style>
有人知道为什么吗?
使用定义的属性值textAppearance
在样式中的属性值之前应用。 AButton
is a TextView
应用了样式,并且 Button 的默认样式将覆盖您的 textAppearance (例如 Android 2.3 会将其设置为?android:attr/textAppearanceSmallInverse
) and textColor
.
textAppearance
接受样式作为值;android:textAppearance="@style/login_button_text_appearance"
通常正确的方法是设置textAppearance
,但不适合Button
:
如果您要更改Button
,您还应该强制执行自定义背景图像,因为如果不这样做,一个设备将使用深色背景图像(motorola defy),而另一个设备将使用浅色图像(htcdesire),这可能会使文本难以阅读。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)