gpt4 book ai didi

android - android 5.0以下的EditText光标和指针颜色

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

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

我不知道,哪个属性被我的值覆盖了。我有两种选择来遇到这个问题:

  1. 找到控制该颜色值的属性。
  2. 在页面加载时(在 onViewCreated 中)通过 java 代码更改颜色值。

请建议如何解决此问题。

样式.xml

<?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>

布局.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>

尝试以编程方式添加 View 但没有成功

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);

screenshot

最佳答案

试试这个 link .对我来说,它奏效了。而且,您可以在 SDK 上找到并修改 drawables:Android\sdk\platforms\YOUR_ANDROID_VERSION\data\res at drawables-*dpi

您可以根据需要复制和修改它们的颜色/形式

关于android - android 5.0以下的EditText光标和指针颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240065/

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