BorderTextViews.java

package xiaosi.BorderTextView;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView; public class BorderTextViews extends TextView
{
private Paint paint = null;
private int color = Color.GRAY;
public BorderTextViews(Context context, AttributeSet attrs)
{
super(context, attrs);
}
//设置边框颜色
public void setPaintColor(int color){
this.color = color;
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
paint = new Paint();
//给边框设置颜色
paint.setColor(color);
//上
canvas.drawLine(0, 0, this.getWidth()-1, 0, paint);
//左
canvas.drawLine(0, 0, 0, this.getHeight()-1, paint);
//下
canvas.drawLine(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1, paint);
//右
canvas.drawLine(this.getWidth()-1, 0, this.getWidth()-1, this.getHeight()-1, paint);
}
}

Main_Activity.java

package xiaosi.BorderTextView;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle; public class BorderTextViewActivity extends Activity {
/** Called when the activity is first created. */
private BorderTextViews borderTextView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
borderTextView = (BorderTextViews)findViewById(R.id.Border);
borderTextView.setPaintColor(Color.GRAY);
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#CCFF66"> <xiaosi.BorderTextView.BorderTextViews
android:id="@+id/Border"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#C71585"
android:layout_marginTop="20dp"
android:padding="10dp"
android:layout_gravity="center"
android:text="在画布上画边框" /> </LinearLayout>

预览效果:

Android学习(六) 文本框边框的更多相关文章

  1. Android 下拉列表框、文本框、菜单

    1.下拉列表框(Spinner) 项目布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr ...

  2. android启动activity文本框不获得焦点

    在开发中,常常会碰到这种情况,打开一个activity后,第一个文本框自动获得焦点,同时会弹出软键盘输入框,这样很影响用户体验,现在来看解决方法. 我们先来看看为什么会出现上述情况,原因很简单,文本框 ...

  3. 【学习】文本框输入监听事件oninput

    真实项目中遇到的,需求是:一个文本框,一个按钮,当文本框输入内容时,按钮可用,当删除内容时,按钮不可用. 刚开始用的focus和blur, $(".pay-text").focus ...

  4. android 学习六 构建用户界面和使用控件

    1.常用Android控件最终都会继承自View类 2.ViewGroup是一些布局类列表的基类,包括View和ViewGroup 3.构造界面的三种方法    a.完全使用代码(太灵活,而不好维护) ...

  5. Android学习六---OpenCV for android samples

    搭建好OpenCV4Android环境后,就要着手开发自己的应用了.对于一个没有OpenCV基础的人来开发OpenCV应用确实有点难度,不过我们可以从samples里学起,结合javadoc和万能的网 ...

  6. Android学习六:Socket 使用

    1socket的作用 通过http去获取服务器的数据在有些情况下是行不通的,所有使用socket与服务器通信也是必须掌握的 2.代码 好了上代码,代码中有解释,首先是简单的服务端代码 package ...

  7. openfire Android学习(六)----总结

    Xmpp的一些方法整理到一个工具类中了 XmppConnection.java [java] view plaincopy [java] view plaincopy import java.io.B ...

  8. Android -- 自动完成文本框(可以匹配多个值,并以,结尾)

    1. 

  9. android源代码提示文本框还能输入多少个字符

    public class TestAndroidActivity extends Activity { /** Called when the activity is first created. * ...

随机推荐

  1. redis的五种基本数据类型

    redis基本数据类型 redis一共分为5中基本数据类型:String,Hash,List,Set,ZSet 第一种String String类型是包含很多种类型的特殊类型,并且是二进制安全的.比如 ...

  2. SQLSever 触发器

    /*DML触发器分为: 1. after触发器(之后触发) a. insert触发器 b. update触发器 c. delete触发器*/ /*UPDATE 触发器创建触发的语法*/ CREATE ...

  3. WPF的webBrowser控件关键代码

    1.根据元素ID获取元素的值. 比如要获取<img class="" id="regimg" src="/register/checkregco ...

  4. 8.OpenStack网络组件

    添加网络组件 安装和配置控制器节点 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE neutron; GRANT ALL PRIVILEGES ON neut ...

  5. 【linux高级程序设计】(第十四章)TCP高级应用 2

    socket多路复用应用 int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct time ...

  6. 【linux高级程序设计】(第十二章)Linux多线程编程 2

    线程同步机制 互斥锁通信机制 int pthread_mutex_init (pthread_mutex_t *__mutex, __const pthread_mutexattr_t *__mute ...

  7. 在C#中将数字转换成中文

    上篇我们讲了在MSSQL中将数字转换成中文,这篇我们讲讲在C#中将数字转换成中文 下篇将讲一下如何将金额转换成中文金额,废话不多说,具体代码如下: /// <summary> /// 数字 ...

  8. 浅谈JavaScript中的null和undefined

    浅谈JavaScript中的null和undefined null null是JavaScript中的关键字,表示一个特殊值,常用来描述"空值". 对null进行typeof类型运 ...

  9. UNION UNION-ALL

    The UNION ALL operator may be what you are looking for. With this operator, you can concatenate the ...

  10. static静态变量-投票案例

    public class Voter { String name; //名字 private static int count; //投票数 public Voter() {} public Vote ...