天天看点

Android--去除EditText边框,添加下划线

Android--去除EditText边框,添加下划线

<span style="font-family: arial, helvetica, sans-serif;"><?xml version="1.0" encoding="utf-8"?>    </span>  

Android--去除EditText边框,添加下划线

<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,可以设置字体颜色

加下划线

Android--去除EditText边框,添加下划线

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);  

         }  

 }  

转载:http://blog.csdn.net/chaoyu168/article/details/50698197

继续阅读