问题描述
我有以下 EditText
<EditText
android:layout_width="300dp"
android:layout_height="80dp"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:layout_gravity="end"
android:textCursorDrawable="@drawable/hammer_cursor"
android:layout_margin="10dp"
android:textIsSelectable="false"
android:longClickable="false"
android:textColor="#858383"
android:background="@drawable/backer"
android:textSize="14sp"
android:id="@+id/name"
android:padding="10dp"
android:hint="message"
android:textColorHint="#CDCDCD"
tools:ignore="SmallSp"
/>
在框架布局中.我正在尝试将光标变成锤子,但是尽管可以在 hdpi
, mdpi
, xhdpi
中使用锤子可绘制,甚至可以将锤子-来自 android:textCursorDrawable ="@ drawable/hammer_cursor"
的图像,较小的可绘制对象无法正确缩放以适合光标(即使使用较小的锤子图像正确缩放也仍然模糊).android中的 EditText-cursor-drawable 是否有标准尺寸(因此我会相应地生成锤子图像),或者如何正确设置可绘制对象以适合光标而不会出现任何拉伸或模糊锤子图像.
in a framelayout. I am trying to make the cursor a hammer but despite having the hammer-drawable available in hdpi
,mdpi
,xhdpi
or even making the hammer-image from android:textCursorDrawable="@drawable/hammer_cursor"
smaller the drawable fails to scale correctly to fit the cursor(even when it scales correctly with a smaller hammer-image, it's still blurry). Is there a standard dimension for the EditText-cursor-drawable in android(so I make the hammer-image accordingly) or how can the drawable be set correctly to fit the cursor without any stretching or blurriness of the hammer-image.
推荐答案
从您的代码中删除此行 android:hint ="Message"
.使用矢量图像代替任何其他图像类型.在名为 hammer_cursor.xml
的可绘制forlder中创建新文件,并将此代码放入该文件中.
Remove android:hint="Message"
this line from your code.Use vector image instead of any-other image type.Make new file in your drawable forlder named hammer_cursor.xml
and put this code inside this file.
以下是锤子图像的一些示例:
Here is some example of hammer image:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="31dp"
android:height="31dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:name="path"
android:pathData="M 486.391 195.313 C 480.527 189.449 471.039 189.449 465.176 195.313 L 454.57 205.918 L 433.355 184.703 L 369.719 248.344 L 390.93 269.559 L 380.324 280.164 C 374.461 286.027 374.461 295.516 380.324 301.379 L 401.539 322.59 C 407.398 328.453 416.891 328.453 422.754 322.59 L 507.605 237.738 C 513.465 231.875 513.465 222.387 507.605 216.523 Z M 486.391 195.313 M 337.898 237.738 L 422.75 152.883 C 428.613 147.023 428.613 137.535 422.75 131.672 L 337.898 46.82 C 307.703 16.625 267.566 0 224.871 0 L 157.586 0 C 150.977 0 145.145 4.32 143.23 10.648 C 141.313 16.977 143.715 23.938 149.27 27.48 L 226.633 79.055 C 235.137 84.805 240.668 93.918 241.68 104.129 C 242.695 114.363 239.102 124.402 231.832 131.672 C 225.969 137.535 225.969 147.023 231.832 152.887 L 316.684 237.738 C 322.547 243.602 332.035 243.602 337.898 237.738 Z M 337.898 237.738 M 242.438 354.41 C 248.301 348.547 248.301 339.059 242.438 333.199 L 178.797 269.559 C 172.938 263.695 163.449 263.695 157.586 269.559 L 125.766 301.379 L 210.617 386.23 Z M 242.438 354.41 M 17.551 409.445 C -5.852 432.844 -5.852 470.898 17.551 494.297 C 40.949 517.695 79.004 517.695 102.402 494.297 L 189.406 407.445 L 104.551 322.59 Z M 17.551 409.445 M 200.008 248.344 L 242.434 205.918 L 306.074 269.559 L 263.648 311.984 Z M 200.008 248.344"
android:fillColor="#000"
android:strokeWidth="1"/>
这篇关于如何设置EditText自定义光标可绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!