Kis*_*ore 14 android cursor android-edittext
想要更改android的edittext游标颜色,必须在所有设备上进行处理
j2e*_*nue 18
我不得不使用这样的drawable:
mycursor.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<size android:width="1dp" />
<solid android:color="@android:color/holo_blue_light"/>
<!--make sure its a solid tag not stroke or it wont work -->
</shape>
Run Code Online (Sandbox Code Playgroud)
在我的编辑文本中,我设置了光标可绘制属性,如下所示:
<EditText
android:id="@+id/et_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cursorVisible="true"
android:textCursorDrawable="@drawable/mycursor"
/>
Run Code Online (Sandbox Code Playgroud)
在所有平台上获取它的方法就是这样.
1 - 在布局文件夹中打开layout.xml.查找编辑文本并进行设置
android:cursorVisible="true"
Run Code Online (Sandbox Code Playgroud)
这将设置低于os版本11的设备的光标
2 - 在drawable文件夹中创建cursor_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<size android:width="1dp" />
<stroke android:color="@color/black"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
3 - 创建文件夹布局-v11
4 - 将layout.xml复制到layout-v11中
5 - 找到你的编辑文本并设置android:textCursorDrawable ="@ drawable/cursor_drawable"
这将使光标显示在所有设备和操作系统上.
| 归档时间: |
|
| 查看次数: |
31898 次 |
| 最近记录: |