Android EditText 自定义
2016-05-04 17:30
453 查看
1、提示内容颜色
2、内容开始位置于左上角
3、自定义光标颜色和粗细,在res/drawable下新建cursor_sytle
3.1 设置EditText的属性:textCursorDrawable
3.2 设置EditText的属性:textCursorDrawable="@null" 则光标的颜色与文本的颜色一致
4、监控EditText是否有输入,且获取输入长度
mEditText.addTextChangedListener(textWatcher);
android:textColorHint="@color/text_gray"
2、内容开始位置于左上角
android:textAlignment="textStart" android:gravity="start"
3、自定义光标颜色和粗细,在res/drawable下新建cursor_sytle
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="1.5dp"/> <solid android:color="@color/blue"/> </shape>
3.1 设置EditText的属性:textCursorDrawable
android:textCursorDrawable="@drawable/cursor_style"
3.2 设置EditText的属性:textCursorDrawable="@null" 则光标的颜色与文本的颜色一致
4、监控EditText是否有输入,且获取输入长度
mEditText.addTextChangedListener(textWatcher);
TextWatcher textWatcher = new TextWatcher() { // TextView textView = (TextView)findViewById(R.id.float_window_add); @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() != 0){ mAddTextView.setTextColor(getResources().getColor(R.color.blue)); //EditText有输入时,改变textView的颜色 } } @Override public void afterTextChanged(Editable s) { if (s.length() == 0){ mAddTextView.setTextColor(getResources().getColor(R.color.text_gray)); //输入完毕,若字符长度为空时,为没输入 } } };
相关文章推荐
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)
- android使用代码写布局文件
- Android常用颜色值
- Android自动化压力测试之Monkey Test (三)
- Android Studio查看SHA1和MD5
- Android Studio 使用教程1
- 如何让Android横竖屏切换时不销毁当前activity
- 学习Android Studio开发工具之Activity1
- android标题栏颜色渐变效果的实现(标题栏随着scrollview的滚动而变化)
- 最快学习百度地图android开发的方法探讨--从官方例子开始之问题处理-例子分割
- android 基础 @SuppressLint("NewApi")和@TargetApi()的作用与区别
- android开发期间使用真机调试但系统无法识别出真机
- Android广播机制基础
- android studio断点调试
- Android 6.0 - 动态权限管理的解决方案
- Android 创建一个activity 及创建Intent对象跳转界面并传值
- Android用SharedPreference存储数据
- Android消息传递机制----Handler
- [置顶] Android开发之pdf
- java.lang.ClassCastException: android.widget.*Layout$LayoutParams