【问题标题】:Style not applied when called调用时未应用样式
【发布时间】:2018-11-22 15:41:43
【问题描述】:

所以我是 android 新手,这是我的问题: - 当我将 style 调用到 textview 时,它不会改变任何东西,这是我的 style.xml:

<?xml version="1.0" encoding="utf-8"?>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- App branding color for the app bar -->
    <item name="colorPrimary">#009688</item>
    <!-- Darker variant for the status bar and contextual app bars -->
    <item name="colorPrimaryDark">#00796B</item>
    <!-- Theme UI controls like checkboxes and text fields -->
    <item name="colorAccent">#536DFE</item>
</style>

<!-- Style for header text in the order form -->
<style name="HeaderTextStyle">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">48dp</item>
    <item name="android:gravity">center_vertical</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:textSize">15sp</item>
    <item name="android:textColor">#FF5252</item>
</style>

这就是我如何称呼这种风格

    <TextView
    android:hint="@string/topping"
    style="@style/HeaderTextStyle"
    />

我尝试使用

仅更改文本视图的颜色
android:textColor="#FF5252"

但它什么也没做

有人能帮帮我吗,我会很高兴的, 提前致谢

【问题讨论】:

  • 您已设置提示文本并更改不存在的文本颜色使用标签中的文本而不是提示或使用 textColoHint 而不是 textColor
  • 谢谢它的工作,你能把它作为答案发布,以便我接受它

标签: java android android-studio textview styles


【解决方案1】:

您在设置 textColor 时尚未设置文本,如果您想使用 textColor,则需要将 textColo 更改为 textColorHint 或将提示更改为文本,对于提示您使用 textColorHint,对于文本您使用 textColor 像这样。

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="some text"
            android:textColor="@color/colorPrimaryNero"
            android:hint="some hint"
            android:textColorHint="@color/colorPrimaryWhite" />

【讨论】:

    猜你喜欢
    • 2016-07-24
    • 2011-07-16
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 2019-07-30
    • 2017-04-22
    • 2018-02-28
    • 1970-01-01
    相关资源
    最近更新 更多