【问题标题】:cannot change edittext hint color无法更改编辑文本提示颜色
【发布时间】:2016-02-02 01:58:50
【问题描述】:

我执行自定义 Edittext 如下。我的应用程序提示文本颜色在三星 Galaxy Neo 中不会改变,并且所有提示都隐藏在此编辑文本中。我尝试在 xml 中更改 textHintColor 并尝试过:

nameEditText.setHintTextColor(getResources().getColor(R.color.primary));

但这款手机没有任何变化。

public class EditText extends android.widget.EditText {

    public EditText(Context context) {
        super(context);
        final Typeface tf = Typeface.createFromAsset(context.getAssets(), Constants.APPLICATION_FONT);
        setTypeface(tf);
//        setTextSize(this.getTextSize());
    }

    public EditText(Context context, AttributeSet attrs) {
        super(context, attrs, android.R.attr.editTextStyle);
        final Typeface tf = Typeface.createFromAsset(context.getAssets(), Constants.APPLICATION_FONT);
        setTypeface(tf);
//        setTextSize(this.getTextSize());
    }

    public EditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        final Typeface tf = Typeface.createFromAsset(context.getAssets(), Constants.APPLICATION_FONT);
        setTypeface(tf);
//        setTextSize(this.getTextSize());
    }

我也更改了应用主题,但没有任何变化。 这是edittext的用法:

  <com.myproj.widget.EditText
                    style="@style/Text.SettingItem"
                    android:id="@+id/emailEditText"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="start"
                    android:hint="@string/hint_email"
                    android:inputType="textEmailAddress"
                    android:maxLength="40"
                    android:singleLine="true" />

【问题讨论】:

标签: android colors edit hint


【解决方案1】:

只需将此添加到 EditText 的布局中:

android:textColorHint="#FFFFFF" // any color

或者您可以从颜色资源文件中设置颜色

android:textColorHint="@color/red"

【讨论】:

  • 你能在这里发布你的xml代码吗.. //从java端删除所有代码并只在xml中添加这一行..它应该可以工作..我现在已经测试过了。它正在工作..
  • 我更新了问题,但我知道它应该可以工作,但似乎有些东西覆盖了我的代码。
【解决方案2】:

有没有在你的xml中声明背景?我有一个类似的问题,答案是背景大小错误,你可以删除它来测试

【讨论】:

    【解决方案3】:
        <item name="colorAccent">@android:color/black</item>
    

    将您的 colorAccent 更改为您在主题中所需的颜色,这将更改您的 EditText 行、光标以及您的提示

    或者你也可以在你的 style.xml 中包含这个样式

    <style name="TextLabel" parent="TextAppearance.AppCompat">
        <!-- Hint color and label color in FALSE state -->
        <item name="android:textColorHint">@android:color/black</item>
        <item name="android:textSize">20sp</item>
        <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
        <item name="colorAccent">@android:color/black</item>
        <item name="colorControlNormal">@android:color/black</item>
        <item name="colorControlActivated">@android:color/black</item>
    </style>
    

    然后在您的 TextInputLayout 中,您可以这样放置

    <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/TextLabel">
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:drawableLeft="@drawable/password"
                    android:drawableStart="@drawable/password"
                    android:maxLines="1"
                    android:hint="password"
                    android:inputType="textWebPassword" />
    
            </android.support.design.widget.TextInputLayout>
    

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 2011-02-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      相关资源
      最近更新 更多