EditText就像Note

时间:2017-07-03 08:24:37

标签: android android-edittext notepad

我正在开发类似Note App的Android应用程序。所有的事情都很顺利。这是我的输出。

documentation

但是,当我输入缅甸语(东南亚语言之一)时,我遇到了一个问题,即我的EditText中的行与文本不一致,这是我的输出,

enter image description here 我用Google搜索并尝试了很多方法。但是,它无法帮助我。以下是我的代码。麻烦!

LinedEditText.java

public class LinedEditText extends android.support.v7.widget.AppCompatEditText {
    private Rect mRect;
    private Paint mPaint;

    // we need this constructor for LayoutInflater
    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);

        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(0x800000FF);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int height = getHeight();
        int line_height = getLineHeight();

        int count = height / line_height;

        if (getLineCount() > count)
            count = getLineCount();

        Rect r = mRect;
        Paint paint = mPaint;
        int baseline = getLineBounds(0, r);

        for (int i = 0; i < count; i++) {

            canvas.drawLine(r.left, baseline + 2, r.right, baseline + 2, paint);
            baseline += getLineHeight();
        }
        super.onDraw(canvas);

    }

}

actvity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:maxLength="10"
        android:ems="10"
        android:hint="Title Here" />

    <login.fb.ucsy.com.notepad.LinedEditText
        android:id="@+id/edit_story"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:background="@null"
        android:inputType="textMultiLine|textNoSuggestions"
        android:minLines="10"
        android:gravity="top|left"
        android:singleLine="false"
        android:imeOptions="actionNone"
        android:text="Story : \n"  />

</LinearLayout>

0 个答案:

没有答案