我个人不费话,内容如题,以下是代码:
package com.puppet.custom.component;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.widget.EditText;

public class SearchEditText extends EditText{
private Paint paint;
public SearchEditText(Context context) {
super(context);
//定义画笔
paint = getPaint();
//定义笔画粗细样式
paint.setStyle(Paint.Style.STROKE);
//定义笔画颜色
paint.setColor(Color.GRAY);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int w = getWidth();
int h = getHeight();
//下边框
canvas.drawLine(0, h, w, h, paint);
//右边框
canvas.drawLine(w, 0, w, h, paint);
//左边框
canvas.drawLine(0, 0, 0, h, paint);
//上边框
canvas.drawLine(0, 0, w, 0, paint);
}
}


以下是该控件的引用
package com.puppet.activity;

import com.puppet.custom.component.SearchEditText;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.EditText;
import android.widget.LinearLayout;

public class TestLayout extends LinearLayout{

public TestLayout(Context context) {
super(context);
//设背景色为白色
setBackgroundColor(Color.WHITE);
setOrientation(LinearLayout.VERTICAL);

testBox = new SearchEditText(context);
//设置背景为"@null"
testBox.setBackgroundColor(0);
//设置显示(宽、高)
LayoutParams sbLp = new LayoutParams(300,LayoutParams.WRAP_CONTENT);
//设置边界,以便查看上边框样式
sbLp.topMargin = 5;
//居中显示
sbLp.gravity = Gravity.CENTER;
//设置该样式
testBox.setLayoutParams(sbLp);
testBox.setHint( "请从这里输入...");
//添加到布局
addView(testBox);

}
private EditText testBox = null;
}

下面是Activity的引用:
package com.puppet.activity;

import android.app.Activity;
import android.os.Bundle;

public class TestActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

TestLayout test = new TestLayout(TestActivity. this);
setContentView(test);
}
}


更多相关文章

  1. Android必会小功能总结
  2. ListView多次调用getView方法
  3. android camera根据屏幕图像大小设置显示
  4. android自定义dialog样式
  5. android Paint 设置线宽setStrokeWidth()的单位
  6. Android设置StatusBar颜色
  7. android 设置progressbar的背景颜色
  8. android下tcp之client测试
  9. android 4.0 browser useragent debug

随机推荐

  1. android 中如何分析内存泄漏
  2. Android背景图片平铺
  3. Android MediaPlayer音乐播放
  4. Android中使用Gson解析JSON数据
  5. Android原生弹框的工具类AlertDialog,Dial
  6. Android zxing change orientation to po
  7. Git 一些关于 Git、Github 的学习资源
  8. 录音11
  9. android requestFocus的使用
  10. Android SyncManager 实现