1. 程式人生 > >Android--去除EditText邊框,加入下劃線

Android--去除EditText邊框,加入下劃線

span pos extc get add res blog new attrs

<span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0" encoding="utf-8"?>    </span>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="fill_parent"    
    android:layout_height="fill_parent"    
    >    
<!--註意名稱 -->    
<com.marine.study.LineEditText     
        
    android:id="@+id/myEdit"    
    android:layout_width="fill_parent"     
    android:layout_height="wrap_content"     
    style="?

android:attr/textViewStyle" android:background="@null" android:textColor="@null" /> </LinearLayout>


當中background,能夠設置成其它顏色等

textColor不一定要是null,能夠設置字體顏色


加下劃線

public class LineEditText extends EditText {
      // 畫筆 用來畫下劃線
    private Paint paint;
  
      public LineEditText(Context context, AttributeSet attrs) {
          super(context, attrs);
          paint = new Paint();
          paint.setStyle(Paint.Style.STROKE);
          paint.setColor(Color.RED);
         // 開啟抗鋸齒 較耗內存
         paint.setAntiAlias(true);
     }
 
	   @Override
     protected void onDraw(Canvas canvas) {
         super.onDraw(canvas);
         // 得到總行數
         int lineCount = getLineCount();
         // 得到每行的高度
         int lineHeight = getLineHeight();
         // 依據行數循環畫線
         for (int i = 0; i < lineCount; i++) {
             int lineY = (i + 1) * lineHeight;
             canvas.drawLine(0, lineY, this.getWidth(), lineY, paint);
         }
 
     }
 
 }


Android--去除EditText邊框,加入下劃線