Android 给EditText添加下划线
在安卓高版本中,默认是有下划线的,其下划线的颜色是由其主题颜色来控制的
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. --><item name="colorPrimary">@color/colorPrimary</item><item name="colorPrimaryDark">@color/colorPrimaryDark</item>**<item name="colorAccent">@color/colorPrimaryDark</item>**
所以,只需要修改colorAccent的颜色,其下划线的颜色既可以修改!
在低版本中,同样可以添加下划线
方法一:
//此时必须要设置其背景为空
<EditTextandroid:background="@null"android:drawableBottom="@drawable/line"android:layout_width="match_parent"android:layout_height="wrap_content"/>
// drawable/line 是资源名称
<shape xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="@color/colorBlue" /><sizeandroid:height="1dp"android:width="1000dp" />
</shape>
方法二:通过自定义editText
public class UnderLineEditText extends EditText {private Paint paint;public UnderLineEditText(Context context, AttributeSet attrs) {super(context, attrs);//设置画笔的属性paint = new Paint();paint.setStyle(Paint.Style.STROKE);//设置画笔颜色为红色paint.setColor(Color.RED);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);/**canvas画直线,从左下角到右下角,this.getHeight()-2是获得父edittext的高度,但是必须要-2这样才能保证* 画的横线在edittext上面,和原来的下划线的重合*/canvas.drawLine(0, this.getHeight()-2, this.getWidth()-2, this.getHeight()-2, paint);}
}
这里有几点需要注意:
其一:也可以继承android.support.v7.widget.AppCompatEditText,但是有时会出现获取不到焦点的现状
其二:下划线的的位置确定
方法三:使用layer-list来显示边框线,drawable新建资源文件
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><!--底层使用蓝色填充色--><item><shape><solid android:color="#02a0ef"/></shape></item><!--上面一层距离底层的顶部1dp,类似marginTop,填充色为白色,这样就形成了一个带有蓝色顶部边线的白色背景的图--><item android:top="1dp"><shape><solid android:color="#fff"/></shape></item>
</layer-li
Android 给EditText添加下划线相关推荐
- android 下划线edittext,Android实现EditText添加下划线
在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的! 控制如下: @color/colorPrimary @color/colorPrimaryDark **@color/col ...
- linux中文本怎么添加下划线,Android实现EditText添加下划线
在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的! 控制如下: @color/colorPrimary @color/colorPrimaryDark **@color/col ...
- 【Andrid】去掉android中EditText的下划线
去掉android中EditText的下划线 android:background="@null"
- 给EditText添加下划线
在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的! 控制如下: <style name="AppTheme" parent="Theme.A ...
- Android Studio editText去掉下划线的办法
android:background="#00FFFFFF" 在xml中定义EditText中加上这句话把背景设置为透明即可的哈~
- android textView 替文字添加下划线 删除线
android textView 替文字添加下划线 删除线 方法1: tv=(TextView)findViewById(R.id.tv); tv.getPaint().setFlags(Paint. ...
- Android Textview 添加下划线 方法
Android TextView 添加下划线的简单方法 在res的values资源文件夹下,给String.xml文件添加 <string name="userlicense" ...
- 为文字添加下划线和中划线
Android开发中如何给文字添加下划线和中划线呢,先看一下效果图: 下划线: 中划线: 方式一: //添加下划线 // textView.getPaint().setFlags(Paint.UNDE ...
- WebView实现改变选中区域颜色以及添加下划线
一.Web端实现 最近遇到了一个问题,老大要求实现对WebView加载的html页面实现选中修改背景色以及添加下划线并可以删除,最后可以保存这些修改,下次进入该html界面时仍然能够显示之前添加的背景 ...
最新文章
- DllMain中不当操作导致死锁问题的分析--进程对DllMain函数的调用规律的研究和分析
- xslt 标签取集合第一条数据_XSLT函数集合:数值函数、字符串函、节点集函数和布尔函数...
- IDEA 调试部署 Web-INF/classes下面不生成class文件
- leetcode - 1024. 视频拼接
- gitlab 删除仓库
- linq to entity 错误 1 错误 75: 类型 视图名称 的键部分 “主键的列名1”无效。该键的所有部分都必须不可以为 null。(转)...
- 测试用例的优先级概念
- paip.提升性能---mysql 优化cpu多核以及lan性能的关系.
- Android常用播放器对比,谁更好用?四款Android音乐播放器对比
- C语言micstring函数,micSendString函数使用方法
- opencv 应用程序无法正常启动0xc000007b
- 电脑无法进入睡眠的解决方法
- 2021年第四季度全球消费者信心总体持平,印度仍为全球最高,中国大幅增长,日本仍远低于全球平均水平 | 美通社头条...
- mysql报08S01的错误- SQL Error: 0, SQLState: 08S01 偶发
- 黑白琴键 java_黑白琴键上的爱阅读答案
- 视频直播源码_直播平台搭建_直播程序源码——技术架构解析
- 16、什么是拟牛顿法(Quasi-Newton Methods)?
- Android中的Junit单元测试
- git fetch总结
- Autoware1.15 + OpenPlanner2.5 下的laneChange解析(1)
热门文章
- candence的图纸大小设置_AutoCAD中怎样自己设置图纸大小?
- python评论情感分析毕业设计_使用文本挖掘技术进行小说《圣墟》评论的情感分析——基于python...
- SQL简明数据分析教程
- 微信小程序实现换肤功能
- 闲话乱侃——26字母软件开发语言命名是否用完了?
- rapidSVN : Error while performing action: ra_serf: The server sent a truncated HTTP response body.
- 2022秋季C语言专题实验07
- 牛客网SQL实战二刷 | Day10
- 集思录REITs基金数据python爬取写入EXCEL表
- 关于微服务和 Java 需要知道的 5 件事