阅读更多

android 可以任意继承控件而写出自定义的漂亮的控件来。要写自定义的可以需要继续android.widget.EditText,并且重写其它onDraw就可以得到自己的编辑框。

import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.WindowManager; import android.widget.EditText; public class TelEdit extends EditText{ Context mContext; public TelEdit(Context context) { super(context); mContext = context; } public TelEdit(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } public TelEdit(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context; } protected void onDraw(Canvas canvas) { WindowManager wm = (WindowManager) mContext.getSystemService("window"); int windowWidth = wm.getDefaultDisplay().getWidth(); int windowHeight = wm.getDefaultDisplay().getHeight(); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.BLACK); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); int scrollY = getScrollY(); int scrollX = getScrollX()+windowWidth; int innerHeight = scrollY + getHeight() - paddingTop - paddingBottom; int lineHeight = getLineHeight(); int baseLine = scrollY + (lineHeight - (scrollY % lineHeight)); int x = 8; while (baseLine < innerHeight) { //canvas.drawBitmap(line, x, baseLine + paddingTop, paint); canvas.drawLine(x, baseLine + paddingTop,scrollX, baseLine + paddingTop, paint); baseLine += lineHeight; } super.onDraw(canvas); } }

使用如下代码插入:

更多相关文章

  1. Android中禁止多点触控的设置
  2. android:descendantFocusability 焦点 父控件与子控件焦点 .
  3. Android选择框
  4. Android学习笔记(八)
  5. Android(安卓)豆知识
  6. Android中实现控件圆角边框
  7. Android控件之Textiew的使用
  8. android DIY 2
  9. android 做报表的一些控件

随机推荐

  1. MySQL5.7慢查询日志时间与系统时间差8小
  2. 详解mysql8.018在linux上安装与配置过程
  3. 集群rpm安装MySQL步骤详解
  4. Mysql账户管理原理与实现方法详解
  5. Mysql8.0使用窗口函数解决排序问题
  6. dubbo中zookeeper请求超时问题:mybatis+sp
  7. 解决centos下MySQL登录1045问题
  8. mysql charset=utf8你真的弄明白意思了吗
  9. mysql实现事务的提交与回滚的实例详解
  10. MySQL用limit方式实现分页的实例方法