10

EditText カーソル ポインターの色を (原色の青から白に) 変更しようとしていますが、私のプロジェクトでは解決策がありません。同じコードが正常に動作するデモ プロジェクトを開発しようとしました。このコードは >= Android 5.0 で正常に動作しています

どの属性が私の値で上書きされるのかわかりません。この問題に遭遇するには、次の 2 つのオプションがあります。

  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>

プログラムでビューを追加しようとしましたが、成功しませんでした

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

スクリーンショット

4

8 に答える 8

2

この解決策を試してください:

でこの属性を使用しますEditTextandroid:textCursorDrawable="@drawable/cursor_color"

drawable、次を作成します。cursor_color.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<size android:width="1dp" />

<solid android:color="#c8c8c8" />

于 2016-12-20T10:55:20.363 に答える
1

style/themeこれだけのために独自のものを作成し、次EditTextを変更できColorAccentます。

<style name="EditTextColorCustom" parent="@style/AppBaseTheme">
    <!-- Customize your theme here. -->
    <item name="colorAccent">@color/colorAccent</item>
</style>

これをフォルダで使用stylevalues-21ます。

于 2016-12-20T10:52:21.427 に答える