1、简介
本文记录的是Android开发中很常用的EditText 控件的很常用的使用技巧,后续会陆续整理这方面的内容也是更好的熟悉将来的开发。
2、具体案例与效果
2.1 关于光标
2.1.1 对于单个EditText的光标颜色设置:
说明: 该属性还挺使用的,我发现MUI上EditText控件,hint显示的输入和文字输入的光标粗窄不一致。我在项目中一般将光标的宽度设置为 2dp。
android:textCursorDrawable="@drawable/shape_cursor_login"
shape_cursor_login.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/common_dimension_1"/>
<solid android:color="@color/orange_add_pond"/>
</shape>
这样就可以修改单个控件的光标颜色。
拓展
还有就是 EditText的对齐方式会对光标产生影响,右对齐,需要设置光标的left方向上的padding值
2.1.2 对于一个活动或者整个Application的光标颜色的设置
如下,所示在需要的活动或者全局设备相对应的光标颜色即可。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/accent</item>