Android 5.0以下的EditText光标和指针颜色 [英] EditText cursor and pointer color for below android 5.0

查看:444
本文介绍了Android 5.0以下的EditText光标和指针颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将EditText光标指针的颜色(从蓝色的原色更改为白色),但是没有解决方案适用于我的项目。我试图开发演示项目,其中相同的代码可以正常工作。 此代码适用于> = android 5.0

I am trying to change EditText cursor pointer color (from primary color blue to white), but no solution is working for my project. I have tried to develop demo project, where the same code is working fine. This code is working fine for >=android 5.0

我不知道,哪个属性被我的值覆盖。我有两种方法可以解决此问题:-

1.找到控制该颜色值的属性。

2.页面加载时通过Java代码更改颜色值(在onViewCreated中)。

I do not know, which attribute is overridden by my value. I have two options to encounter this problem :-
1. find the attribute which is controlling that color value.
2. change color value by java code when page loads (in onViewCreated).

请建议如何解决此问题。

Please suggest how to resolve this issue.

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

    <style name="my_text_layout_style">

        <item name="android:textColor">#FFF</item>
        <item name="android:textColorHint">#FFF</item>

        <item name="colorAccent">#FFF</item>
        <item name="colorControlNormal">#FFF</item>
        <item name="colorControlActivated">#FFF</item>

        <item name="colorControlHighlight">#FFF</item>

    </style>



    <style name="my_edit_text_style">
        <item name="colorAccent">#FFF</item>
        <item name="android:editTextStyle">@style/MyEditTextStyle</item>
    </style>

    <style name="MyEditTextStyle" parent="Widget.AppCompat.EditText" />
</resources>



layout.xml



layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/base_disable_btn_bg_color"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:hint="just a hint"
        app:hintTextAppearance="@style/my_text_layout_style"
        android:theme="@style/my_text_layout_style"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:theme="@style/my_edit_text_style"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>
</LinearLayout>



试图以编程方式添加视图,但没有成功



Tried to add view programmatically but no success

AppLinearLayout appLinearLayout = (AppLinearLayout) view.findViewById(R.id.some_id);
EditText editText = new EditText(new ContextThemeWrapper(getContext(), R.style.AppTheme_Cursor));
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(params);
appLinearLayout.addView(editText);

推荐答案

尝试以下链接。对我来说,它奏效了。
而且,您可以在以下位置找到并修改 SDK 中的可绘制对象 Android的SDK平台\YOUR_ANDROID_VERSION\数据以drawables- * dpi 格式运行。

Try this link. For me, it worked. And, you can find and modify the drawables on your SDK here: Android\sdk\platforms\YOUR_ANDROID_VERSION\data\res at drawables-*dpi.

您可以复制并修改他们的颜色/表格如您所愿。

You can copy and modify their color/form as your wish.

这篇关于Android 5.0以下的EditText光标和指针颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆