自定义EditText编辑框
2016-06-27 08:26
381 查看
package com.example.administrator.app3; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.Gravity; import android.widget.EditText; /** * Created by Administrator on 2016/6/17 0017. * 继承编辑框控件 */ public class MyNotePad extends EditText { private Paint paint; public MyNotePad(Context context) { super(context); init(); } public MyNotePad(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { paint = new Paint(); paint.setAntiAlias(true); paint.setStrokeWidth(2); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); this.setGravity(Gravity.TOP);//从上面开始写 this.setBackgroundColor(Color.TRANSPARENT);//背景颜色 int height = getHeight();//高度 int width = getWidth();//宽度 int lineHeight=getLineHeight();//每一行的高度 int lines=height/lineHeight;//显示多少行 for(int i=0;i<lines;i++){ canvas.drawLine(0,(i+1)*lineHeight+lineHeight/2,width,(i+1)*lineHeight+lineHeight/2,paint); } int count=getLineCount();//获取总行数 if(count>lines){ //在原来的基础上增加 for(int i=0;i<count;i++){ canvas.drawLine(0,(i+1)*lineHeight+lineHeight/2,width,(i+1)*lineHeight+lineHeight/2,paint); } } } }
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.administrator.app3.MainActivity"> <com.example.administrator.app3.MyNotePad android:layout_width="match_parent" android:layout_height="match_parent" /> </ScrollView>
相关文章推荐
- Android Native 绘图方法
- flex 控件的重要属性
- 麻雀虽小五脏俱全 Dojo自定义控件应用
- 学习Winform文本类控件(Label、Button、TextBox)
- Delphi控件ListView的属性及使用方法详解
- C#中struct和class的区别详解
- web下载的ActiveX控件自动更新
- WinForm自定义控件应用实例
- WinForm实现按名称递归查找控件的方法
- VBS ArrayList Class vbs中的数组类
- 大家看了就明白了css样式中类class与标识id选择符的区别小结
- C#中父窗口和子窗口之间控件互操作实例
- C#编写ActiveX网页截图控件
- Android编程之Button控件用法实例分析
- Android控件之CheckBox、RadioButton用法实例分析
- 在Android开发中使用自定义组合控件的例子
- 一款超酷的Android自定义加载控件
- Android组合控件实现功能强大的自定义控件
- Android重写View实现全新的控件
- C++ 自定义控件的移植问题