24

そこで、HoloColorsGeneratorとActionBarStyleGeneratorを使用してHoloThemeのスタイルを自分の色に変更しまし。しかし、編集テキスト内のテキストを選択すると、選択した位置の「マーカー」はまだ青色のままです。どうすれば変更できますか?

左真ん中右

4

7 に答える 7

38

ここでの最悪の部分は、このアイテムの「名前」と、テーマ内での名前の付け方を見つけることでした。そこで、Android SDKフォルダー内のすべてのドローアブルを調べて、最終的に「text_select_handle_middle」、「text_select_handle_left」、「text_select_handle_right」という名前のドローアブルを見つけました。

したがって、解決策は簡単です。カスタマイズされたデザイン/色のこれらのドローアブルをドローアブルフォルダに追加し、次のようにテーマスタイル定義に追加します。

<style name="MyCustomTheme" parent="@style/MyNotSoCustomTheme">
        <item name="android:textSelectHandle">@drawable/text_select_handle_middle</item>
        <item name="android:textSelectHandleLeft">@drawable/text_select_handle_left</item>
        <item name="android:textSelectHandleRight">@drawable/text_select_handle_right</item>
</style>
于 2013-02-28T11:07:41.127 に答える
13

コードからそれを行う方法:

try {
    final Field fEditor = TextView.class.getDeclaredField("mEditor");
    fEditor.setAccessible(true);
    final Object editor = fEditor.get(editText);

    final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft");
    final Field fSelectHandleRight =
        editor.getClass().getDeclaredField("mSelectHandleRight");
    final Field fSelectHandleCenter =
        editor.getClass().getDeclaredField("mSelectHandleCenter");

    fSelectHandleLeft.setAccessible(true);
    fSelectHandleRight.setAccessible(true);
    fSelectHandleCenter.setAccessible(true);

    final Resources res = context.getResources();

    fSelectHandleLeft.set(editor, res.getDrawable(R.drawable.text_select_handle_left));
    fSelectHandleRight.set(editor, res.getDrawable(R.drawable.text_select_handle_right));
    fSelectHandleCenter.set(editor, res.getDrawable(R.drawable.text_select_handle_middle));
} catch (final Exception ignored) {
}
于 2014-12-05T00:53:22.290 に答える
13

これは本当に遅いと思いますが、ハンドルの色を変更するだけの場合は、styles.xmlファイルに次を追加するだけです。

<style name="ColoredHandleTheme">
    <item name="colorControlActivated">@color/colorYouWant</item>
</style>

EditTextそして、あなたが影響を与えたいと思っている活動が何であれ、テーマを設定するだけです。

または、アプリ全体に設定する場合は、次の操作を実行できます。

<style name="ColoredHandleThemeForWholeApp">
    <item name="colorAccent">@color/colorYouWant</item>
</style>

そして、アプリ全体にそのテーマを設定します。

問題が解決しました!

于 2016-11-28T16:57:42.573 に答える
7

選択したハンドルの色を変更するには、アプリのテーマでアクティブになっている色を上書きする必要があります。

<style name="MyCustomTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:colorControlActivated">@color/customActivatedColor</item>
</style>
于 2017-01-26T11:10:05.703 に答える
2

これらの属性はhttp://androiddrawables.com/Other.htmlで確認できます。

たとえば、values/styles.xmlを変更します。

<style name="AppTheme.Cursor" parent="AppTheme">
    <item name="colorAccent">@color/cursor</item>
</style>

ここで、@ color/cursorはvalues/color.xmlに追加されます。その後、スタイルをアクティビティに適用します。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.AppTheme_Cursor);
    ...

他の解決策については、(カーソルではなく) EditTextポインターの色を変更する方法を参照してください。

于 2015-12-08T16:44:07.327 に答える
1

コードからこれを処理しようとする人のために、28以下のAPIバージョンに対してJared Rummlerによって提供された回答を使用できますが、Android Q(API 29)から、@ UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P )アノテーションがあり、Q+では機能しないようです。代わりに、EditTextに追加された新しいメソッド:

setTextSelectHandle(R.drawable.test);
setTextSelectHandleLeft(R.drawable.test);
setTextSelectHandleRight(R.drawable.test);

したがって、それを機能させるには、次のようなことを行うことができます。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                setTextSelectHandle(R.drawable.test);
                setTextSelectHandleLeft(R.drawable.test);
                setTextSelectHandleRight(R.drawable.test);
            } else {
                try {
                    final Field fEditor = TextView.class.getDeclaredField("mEditor");
                    fEditor.setAccessible(true);
                    final Object editor = fEditor.get(this);

                    final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft");
                    final Field fSelectHandleRight =
                            editor.getClass().getDeclaredField("mSelectHandleRight");
                    final Field fSelectHandleCenter =
                            editor.getClass().getDeclaredField("mSelectHandleCenter");

                    fSelectHandleLeft.setAccessible(true);
                    fSelectHandleRight.setAccessible(true);
                    fSelectHandleCenter.setAccessible(true);

                    final Resources res = getResources();

                    fSelectHandleLeft.set(editor, res.getDrawable(R.drawable.test, null));
                    fSelectHandleRight.set(editor, res.getDrawable(R.drawable.test, null));
                    fSelectHandleCenter.set(editor, res.getDrawable(R.drawable.test, null));
                } catch (final Exception ignored) {
                }
            }
于 2020-07-27T18:42:50.560 に答える
0

1つのEditTextでのみポインターを非表示にする場合は、それにのみテーマを設定できます。

styles.xml

<style name="TransparentPointerEditText">
    <item name="colorControlActivated">@android:color/transparent</item>
</style>

利用方法

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/TransparentPointerEditText" />
于 2021-11-18T14:24:34.850 に答える