gpt4 book ai didi

Android按钮文字外观

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:10:51 24 4
gpt4 key购买 nike

我可以通过在对象中设置它来更改按钮文本的外观,如下所示:

<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 定义的属性值在样式中的属性值之前应用。 Button 是一个应用了样式的 TextView,Button 的默认样式将覆盖您的 textAppearance(例如 Android 2.3 会将其设置为 ?android: attr/textAppearanceSmallInverse) 和 textColor

textAppearance 接受样式作为值; android:textAppearance="@style/login_button_text_appearance" 通常是设置 textAppearance 的正确方法,但不是 Button:

如果您要更改 Button 的文本颜色,您还应该强制使用自定义背景图片,因为如果不这样做,一台设备将使用深色背景图片 (motorola defy) 并且另一个将使用浅色图像 (htc desire),这可能会使文本难以阅读。

关于Android按钮文字外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8245259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com