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的颜色,其下划线的颜色既可以修改!
在低版本和高版本中,同样是可以去添加下划线的!方法有二:
方法一:
//此时必须要设置其背景为空
<EditText
android:background="@null"
android:drawableBottom="@drawable/line"
android:hint="请输入您的手机号码"
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" />
<size
android: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);
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
/**canvas画直线,从左下角到右下角,this.getHeight()-2是获得父edittext的高度,但是必须要-2这样才能保证
* 画的横线在edittext上面,和原来的下划线的重合
*/
canvas.drawLine(, this.getHeight()-, this.getWidth()-, this.getHeight()-, paint);
}
}
这里有几点需要注意:
其一:也可以继承android.support.v7.widget.AppCompatEditText,但是有时会出现获取不到焦点的现状
其二:下划线的的位置确定
Android 给EditText添加下划线的更多相关文章
- React-Native 之 GD (二十)removeClippedSubviews / modal放置的顺序 / Android 加载git图\动图 / 去除 Android 中输入框的下划线 / navigationBar
1.removeClippedSubviews 用于提升大列表的滚动性能.需要给行容器添加样式overflow:’hidden’.(Android已默认添加此样式)此属性默认开启 这个属性是因为在早期 ...
- iOS开发-UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选择 ...
- vim显示行号、语法高亮、自动缩进、添加下划线的设置
ubuntu默认是没有安装vim的,所以设置以前请先安装vim:sudo apt-get install vim. 然后 打开vim的配置文件:sudo vim /etc/vim/vimrc 或者 s ...
- IOS UIlabel 、UIButton添加下划线
1.给UILabel 添加下划线 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )]; label.backgrou ...
- UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的 NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选 ...
- "为文本添加下划线"组件:<u> —— 快应用组件库H-UI
 <import name="u" src="../Common/ui/h-ui/text/c_tag_underline"></impor ...
- Android EditText如何去除边框添加下划线
(一)问题 之前的自定义EditText只能显示高度不超过屏幕高度的文本内容,继续增加内容会出现如下问题: (二)原因分析 下部(超出屏幕高度的部分)没有继续画线,也就是说横线没有画够,那么一定是循环 ...
- Android自定义EditText去除边框并添加下划线
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android 去除EditText边框,添加下划线,
首先:重写EditText //请在这里添加您的包名 import android.content.Context; import android.graphics.Canvas; import an ...
随机推荐
- luogu3704 [SDOI2017]数字表格(莫比乌斯反演)
link 设\(f_0=0,f_1=1,f_n=f_{n-1}+f_{n-2}(n\ge 2)\) 求\(\prod_{i=1}^n\prod_{j=1}^mf_{\gcd(i,j)}\),多组询问, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- PAT天梯赛L1-054 福到了
题目链接:点击打开链接 "福"字倒着贴,寓意"福到".不论到底算不算民俗,本题且请你编写程序,把各种汉字倒过来输出.这里要处理的每个汉字是由一个 N x N 的 ...
- 使用windows服务修改CPU型号(重启依然有效)
此项目基于.net framework 4.0 效果如下: 服务运行前: 服务运行后: 思路大概是这样: 通过修改注册表可以修改CPU型号,把服务设置成本地服务,并且开机自动启动,来实现开机自动修改处 ...
- [USACO18JAN]Cow at Large G(树形DP)
P4186 [USACO18JAN]Cow at Large G(树形DP) Luogu4186 设dp[i]表示i点需要放多少个农民.则有 \(if(near[i]-dep[i]<=dep[i ...
- 在基于AngularJs架构的ABP项目中使用UEditor
[前提须知] 读过此篇博客 了解angular-ueditor 了解ABP如何使用 会使用VS2017 [1.下载ABP模板] https://aspnetboilerplate.com/Templa ...
- Codeforces Round #482 (Div. 2) C 、 Kuro and Walking Route(dfs)979C
题目链接:http://codeforces.com/contest/979/problem/C 大致题意 给出n个点,有n-1个边将他们链接.给出x,y,当某一路径中出现x....y时,此路不通.路 ...
- 75th LeetCode Weekly Contest All Paths From Source to Target
Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and re ...
- 机器学习KNN实例之数字识别
- MessageFormat 格式化String
public static String buildFailureString(AtomicInteger count, String cause) { return MessageFormat.fo ...