Android学习(六) 文本框边框
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学习(六) 文本框边框的更多相关文章
- Android 下拉列表框、文本框、菜单
1.下拉列表框(Spinner) 项目布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr ...
- android启动activity文本框不获得焦点
在开发中,常常会碰到这种情况,打开一个activity后,第一个文本框自动获得焦点,同时会弹出软键盘输入框,这样很影响用户体验,现在来看解决方法. 我们先来看看为什么会出现上述情况,原因很简单,文本框 ...
- 【学习】文本框输入监听事件oninput
真实项目中遇到的,需求是:一个文本框,一个按钮,当文本框输入内容时,按钮可用,当删除内容时,按钮不可用. 刚开始用的focus和blur, $(".pay-text").focus ...
- android 学习六 构建用户界面和使用控件
1.常用Android控件最终都会继承自View类 2.ViewGroup是一些布局类列表的基类,包括View和ViewGroup 3.构造界面的三种方法 a.完全使用代码(太灵活,而不好维护) ...
- Android学习六---OpenCV for android samples
搭建好OpenCV4Android环境后,就要着手开发自己的应用了.对于一个没有OpenCV基础的人来开发OpenCV应用确实有点难度,不过我们可以从samples里学起,结合javadoc和万能的网 ...
- Android学习六:Socket 使用
1socket的作用 通过http去获取服务器的数据在有些情况下是行不通的,所有使用socket与服务器通信也是必须掌握的 2.代码 好了上代码,代码中有解释,首先是简单的服务端代码 package ...
- openfire Android学习(六)----总结
Xmpp的一些方法整理到一个工具类中了 XmppConnection.java [java] view plaincopy [java] view plaincopy import java.io.B ...
- Android -- 自动完成文本框(可以匹配多个值,并以,结尾)
1.
- android源代码提示文本框还能输入多少个字符
public class TestAndroidActivity extends Activity { /** Called when the activity is first created. * ...
随机推荐
- [LA_3938]最大连续动态和
Sample Input 3 1 1 2 3 1 1 Sample Output Case 1: 1 1 线段树 L,R表示该区间的左右端点,sum表示该区间值的总和 l,r表示该区间连续的最大和的左 ...
- android hook 框架 xposed 如何实现挂钩
Android so注入-libinject2 简介.编译.运行 Android so注入-libinject2 如何实现so注入 Android so注入-Libinject 如何实现so注入 A ...
- UVA 10803 Thunder Mountain
纠结在这句话了If it is impossible to get from some town to some other town, print "Send Kurdy" in ...
- Linux操作系统的权限代码分析【转】
转自:http://blog.csdn.net/lixuyuan/article/details/6217502 现在关于内核的书很少涉及到Linux内核的安全,内核安全大概包括了密码学实现(cryp ...
- ubuntu启动脚本一览分析
#rc--run command的意思[rc解释]harvey@ubuntu:/etc$ cat ./init/rc-sysinit.conf # rc-sysinit - System V init ...
- Profile 的翻译
最近要翻译一个英文网站的单词,正宗的英文网站总是有很多单词让我烦恼,这就是其中一个. 特地转一篇文章,对我大有帮助. 计算机中常用的 Profile 该如何理解? 我认为 Profile 即可作名词又 ...
- AC日记——Two poj 1849
Two 思路: 树形DP求直径: 答案是边权总和*2-直径: dp[i][1]::以i为根的子树中最长的路径: dp[i][0]::以i为根的子树中次长的路径: 来,上代码: #include < ...
- (11)oracle触发器
触发器是特殊的存储过程. 每当一个特定的数据操作语句(inster,update,delete)在指定的表上触发时,Oracle自动的地执行触发器中定义的语句序列. create trigger 触发 ...
- (1)C#工具箱-公共控件1
公共控件 InitializeComponent() 先说下InitializeComponent()这个方法,它在form1.cs里调用这个方法对控件进行初始化,控件的方法要在这个方法之后,否则会因 ...
- Southern African 2001 框架折叠 (拓扑序列的应用)
本文链接:http://www.cnblogs.com/Ash-ly/p/5398377.html 题目:考虑五个图片堆叠在一起,比如下面的9 * 8 的矩阵表示的是这些图片的边缘框. 现在上面的图片 ...