zoukankan      html  css  js  c++  java
  • Android关于实现EditText中加多行下划线的的一种方法

    1. 重写EditText

    public class LinedEditText extends EditText {
         private Paint linePaint;
         private float margin;
         private int paperColor;
     
         public LinedEditText(Context paramContext, AttributeSet paramAttributeSet) {
             super(paramContext, paramAttributeSet);
             this.linePaint = new Paint();
         }
     
         protected void onDraw(Canvas paramCanvas) {
             paramCanvas.drawColor(this.paperColor);
             int i = getLineCount();
             int j = getHeight();
             int k = getLineHeight();
             int m = 1 + j / k;
             if (i < m)
                 i = m;
             int n = getCompoundPaddingTop();
             paramCanvas.drawLine(0.0F, n, getRight(), n, this.linePaint);
             for (int i2 = 0;; i2++) {
                 if (i2 >= i) {
                     setPadding(10 + (int) this.margin, 0, 0, 0);
                     super.onDraw(paramCanvas);
                     paramCanvas.restore();
                     return;
                 }
                 n += k;
                 paramCanvas.drawLine(0.0F, n, getRight(), n, this.linePaint);
                 paramCanvas.save();
             }
         }
     
     }

    这段代码,并不复杂没有加注释,学过Java的同学应该不会吃力。

    2.在布局文件中使用

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical" >
     
         <com.example.storetest.LinedEditText
             android:id="@+id/et1"
             android:layout_width="fill_parent"
             android:layout_height="200dp"
             android:gravity="top"
             android:inputType="textMultiLine" />
     
     </LinearLayout>

    注意:使用EditText控件时,不再使用EditText前缀,而是重写之后完整路径的包名+类名(如com.example.storetest.LinedEditText)。

    3.在使用时与正常调用EditText时一致。

  • 相关阅读:
    EntityFramework的安装
    利用Xml架构生成实体访问类
    C#生成XSD规范
    利用Vistual Studio自带的xsd.exe工具,根据XML自动生成XSD
    在.net中序列化读写xml方法的总结
    MVP设计模式的实现
    c#万能视频播放器
    libavcodec是一款LGPL自由软件编解码库,用于视频和音频数据的编解码工作
    用C#实现多种方式播放Wav声音
    Using the G711 standard
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5814681.html
Copyright © 2011-2022 走看看