Android自己定义视图(一):带下划线的TextView
package com.francis.underlinetextviewtest; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.widget.TextView; /**
* Created by Francis on 14-10-13.
*/
public class UnderlineTextView extends TextView { private final Paint mPaint = new Paint();
private int mUnderlineHeight = 0; public UnderlineTextView(Context context) {
this(context, null);
} public UnderlineTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
} public UnderlineTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
} private void init(Context context, AttributeSet attrs) {
Resources r = getResources();
// mUnderlineHeight == 6
mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, r.getDisplayMetrics());
} @Override
public void setPadding(int left, int top, int right, int bottom) {
super.setPadding(left, top, right, bottom + mUnderlineHeight);
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Draw the underline the same color as the text mPaint.setColor(getTextColors().getDefaultColor());
// 对角线上的两点。 canvas.drawRect(0, getHeight() - mUnderlineHeight, getWidth(), getHeight(), mPaint);
}
}
加入布局文件:
<com.francis.underlinetextviewtest.UnderlineTextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#FFDDDDDD"/>
Android自己定义视图(一):带下划线的TextView的更多相关文章
- TabTopUnderLineLayout【自定义顶部选项卡(带下划线)】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 自定义顶部选项卡布局LinearLayout类,实现带下划线样式的效果. 备注:如果配合Fragment的话,MainActivit ...
- TabTopAutoLayout【自定义顶部选项卡区域(带下划线)(动态选项卡数据且可滑动)】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 自定义顶部选项卡布局LinearLayout类,实现带下划线且可滑动效果.[实际情况中建议使用RecyclerView] 备注:如果 ...
- FragmentTabHostUnderLineDemo【FragmentTabHost带下划线】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 使用FragmentTabHost实现顶部选项卡(带下划线效果)展现. 效果图 代码分析 1.该Demo中采用的是FragmentT ...
- 关于python中带下划线的变量和函数 的意义
总结: 变量: 1. 前带_的变量: 标明是一个私有变量, 只用于标明, 外部类还是可以访问到这个变量 2. 前带两个_ ,后带两个_ 的变量: 标明是内置变量, 3. 大写加下划线的变量: ...
- ANDROID自己定义视图——onLayout源代码 流程 思路具体解释
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 简单介绍: 在自己定义view的时候.事实上非常easy.仅仅须要知道3步骤: 1.測量- ...
- [转]关于python中带下划线的变量和函数的意义
Python 的代码风格由 PEP 8 描述.这个文档描述了 Python 编程风格的方方面面.在遵守这个文档的条件下,不同程序员编写的 Python 代码可以保持最大程度的相似风格.这样就易于阅读, ...
- 【转】关于python中带下划线的变量和函数 的意义
http://www.blogjava.net/lincode/archive/2011/02/02/343859.html 总结: 变量: 1. 前带_的变量: 标明是一个私有变量, 只用于标明 ...
- delphi 仅带下划线的TEdit控件
在做录入框的时候,很希望有一个只带下划线的文本框,网上介绍的很多,有自己做组件的,须不知Delphi下只需要简单设置几个属性即可达到目的.
- geotools导入shp文件到Oracle数据库时表名带下划线的问题解决
问题: 最近在做利用geotools导入shp文件到Oracle表中,发现一个问题Oracle表名带下划线时导入失败,问题代码行: dsOracle.getFeatureWriterAppend(or ...
随机推荐
- POJ 3256 Cow Picnic
Cow Picnic Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 2019 Descri ...
- Flume 启动
Configuration是Flume项目的入口程序了,当我们输入 bin/flume-ng agent --conf conf --conf-file conf/kafka1.properties ...
- Golang 在 Mac、Linux、Windows 下交叉编译
Golang 支持在一个平台下生成另一个平台可执行程序的交叉编译功能. Mac下编译Linux, Windows平台的64位可执行程序: CGO_ENABLED= GOOS=linux GOARCH= ...
- Edge浏览器开发人员工具
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Ch ...
- js一些常用方法
string 增加 IsNullorEmpty : String.prototype.IsNullOrEmpty = function (r) { if (r === undefined || ...
- [译] 我最终是怎么玩转了 Vue 的作用域插槽
原文链接:https://juejin.im/post/5c8856e6e51d456b30397f31#comment 原文地址:How I finally got my head around S ...
- caioj 1082 动态规划入门(非常规DP6:火车票)
f[i]表示从起点到第i个车站的最小费用 f[i] = min(f[j] + dist(i, j)), j < i 动规中设置起点为0,其他为正无穷 (貌似不用开long long也可以) #i ...
- 关于Android手机MTP模式连接的一些设置(win7和ubuntu下,以红米1s为例)
有些手机的MTP模式在电脑上识别不了,须要一些设置才干够,以下就网上收集来的一些设置方法集中贴过来: 一. win7下 參考:http://blog.ammrli.com/?p=1117 1.在设备管 ...
- java内部类的初始化
public class InnerClassTest { /** * @param args */ public static void main(String[] args) { // TODO ...
- Android LruCache 压缩图片 有效避免程序OOM
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9316683 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工, ...