【问题标题】:Android : Hint-text color not changing even after manually setting in XML and/or JavaAndroid:即使在 XML 和/或 Java 中手动设置后,提示文本颜色也不会改变
【发布时间】:2015-12-10 10:41:13
【问题描述】:

我正在开发一个 Android 项目,其中有一个 UI 表单,我正在尝试更改 hint-color

我更改了基础主题中的颜色,该更改在我正在处理的另一个项目中生效,但没有解决这个问题。然后我也尝试直接在Java中设置它,但没有任何改变。我错过了什么或覆盖了这些值。请告诉我。

XML:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/register_travel_transparent_background"
    android:orientation="vertical"
    android:paddingLeft="30dp"
    android:paddingRight="30dp"
    android:paddingTop="22dp">

    <mycompany.gradlecheck.Templates.RobotoTextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="32dp"
        android:background="@drawable/transparent_button_selector"
        android:gravity="right"
        android:text="Register User"
        android:textColor="@color/main_color_grey_700"
        android:textSize="34sp"
        app:typeface="robotoThin" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_account"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/emailAddressTextField"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="@string/emailAddress"
            android:textColorHint="@color/cpb_red"
            app:fletFloatingHint="@string/emailAddress"
            app:fletHintTextColor="@color/cpb_red"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_account"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/firstNameTextField"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="@string/firstName"
            app:fletFloatingHint="@string/firstName"
            app:fletHintTextColor="@color/main_color_grey_300"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_password"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/passwordTextField"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="@string/password"
            app:fletFloatingHint="@string/password"
            app:fletHintTextColor="@color/main_color_grey_300"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_password"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/passwordAgainTextField"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="@string/repeatPassword"
            app:fletFloatingHint="@string/repeatPassword"
            app:fletHintTextColor="@color/main_color_grey_300"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_password"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/userCity"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="City"
            app:fletFloatingHint="City"
            app:fletHintTextColor="@color/main_color_grey_300"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_password"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/userCountry"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="Country"
            app:fletFloatingHint="Country"
            app:fletHintTextColor="@color/main_color_grey_300"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <mycompany.gradlecheck.Templates.MaterialDesignIconsTextView
            style="@style/TextViewAppearance.Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="0dp"
            android:text="@string/material_icon_password"
            android:textColor="@color/main_color_grey_300"
            android:textSize="22dp" />

        <mycompany.gradlecheck.Templates.FloatLabeledEditText
            android:id="@+id/ageOfUser"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            android:hint="Age"
            app:fletFloatingHint="Age"
            app:fletHintTextColor="@color/main_color_grey_300"
            app:fletSingleLine="true"
            app:fletTextBackground="@drawable/edit_text_background_accent"
            app:fletTextColor="@color/main_color_grey_700"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/maleRadioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginLeft="20dp"
            android:layout_weight="6.54"
            android:checked="false"
            android:text="Male" />

        <RadioButton
            android:id="@+id/femaleRadioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_weight="0.16"
            android:checked="false"
            android:text="Female" />

    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="22dp"
        android:layout_marginTop="12dp"
        android:gravity="right" >

        <mycompany.gradlecheck.Templates.RobotoTextView
            android:id="@+id/registerUser"
            style="@style/ButtonStyle.RaisedEmpty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:background="@drawable/transparent_button_selector"
            android:minWidth="96dp"
            android:text="@string/register"
            android:textColor="@color/main_color_grey_700"
            app:typeface="robotoMedium" />
    </LinearLayout>
</LinearLayout>

为了确定,我粘贴了完整的 XML。现在的提示色是某种灰白色。

我在 styles.xml 中更改了这个,但没有帮助:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textColorHint">@color/primary_dark_material_dark</item>
</style>

最后我是这样设置的:

    userEmailField.setHintTextColor(Color.parseColor("#000000"));

以上只是变量之一。所有领域都一样。但它仍然没有得到设置。我究竟做错了什么?请告诉我。谢谢你。

【问题讨论】:

    标签: java android xml user-interface


    【解决方案1】:

    我的建议是使用可绘制的颜色本身。所以试试这个:

    userEmailField.setHintTextColor(getResources().getColor(R.color.primary_dark_material_dark));
    

    希望这会有所帮助。

    【讨论】:

    • 抱歉,这并没有改变任何东西。在进行更改后,我还在运行项目之前清理了项目。
    • 您的 FloatLabeledEditText 看起来如何?
    • 我使用您的代码直接在 FloatLabeledEditText 中对其进行了更改,这很有效。它实际上是一个图书馆。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2013-12-19
    • 2019-12-22
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多