这里是我的空间,是我用来记录点滴的沃土...

Androi重写EditText改变边框

View Code
package com.wangsx.Line;

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

public class LineEditText extends EditText {

    private Paint mPaint;

    public LineEditText(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        mPaint = new Paint();

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.WHITE);
    }

    public LineEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        mPaint = new Paint();

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.WHITE);
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // 画底线
        canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, mPaint);
    }
}

 

 

//布局

View Code
    <com.wangsx.Line.LineEditText
        android:id="@+id/myEdit"
        style="?android:attr/textViewStyle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:hint="请填写姓名"
        android:text="你好"
        android:textColor="@null" >
    </com.wangsx.Line.LineEditText>

 

 

//测试

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;

public class LineTextDemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LinearLayout layout = (LinearLayout) findViewById(R.id.ll);

        for (int i = 0; i < 10; i++) {
            LineEditText editText = new LineEditText(this);
            editText.setHint("请输入" + i);
            editText.setTextColor(Color.WHITE);
            editText.setBackgroundColor(Color.TRANSPARENT);
            layout.addView(editText);
        }
    }
}

//效果图

posted @ 2012-06-15 21:14  wsx2miao  Views(3218)  Comments(0Edit  收藏  举报
这里是我的空间,是我用来记录点滴的沃土...