使用类似记事本android的行编辑文本

使用类似记事本android的行编辑文本,android,android-edittext,notepad,Android,Android Edittext,Notepad,我在链接中使用了自定义的EditText类似记事本 在自定义编辑文本中输入的文本在其包含的行中显示不正确。它有时会出现在线上或线下的意外行为 我的输出 所需输出 请帮我解决这个问题 LineEditText.java public class LinedEditText extends EditText { private Rect mRect; private Paint mPaint; // we need this constructor for LayoutIn

我在链接中使用了自定义的
EditText
类似记事本

在自定义编辑文本中输入的文本在其包含的行中显示不正确。它有时会出现在线上或线下的意外行为

我的输出

所需输出

请帮我解决这个问题

LineEditText.java

public class LinedEditText extends EditText {
    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.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#C0C0C0")); //SET YOUR OWN COLOR HERE
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //int count = getLineCount();

        int height = getHeight();
        int line_height = getLineHeight();

        int count = height / line_height;

        if (getLineCount() > count)
            count = getLineCount();//for long text with scrolling

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

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

            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
            baseline += getLineHeight();//next line
        }

        super.onDraw(canvas);
    }
}
公共类LinedEditText扩展了EditText{
私人直肠;
私人油漆;
//我们需要这个构造器来实现LayoutFlater
public LinedEditText(上下文、属性集属性){
超级(上下文,attrs);
mRect=新的Rect();
mPaint=新油漆();
mPaint.setStyle(绘制、样式、填充和笔划);
mPaint.setColor(Color.parseColor(#c0c0”);//在此处设置您自己的颜色
}
@凌驾
受保护的void onDraw(画布){
//int count=getLineCount();
int height=getHeight();
int line_height=getLineHeight();
int count=高度/线条高度;
如果(getLineCount()>count)
count=getLineCount();//用于带滚动的长文本
Rect r=mRect;
油漆油漆=mPaint;
int baseline=getLineBounds(0,r);//第一行
for(int i=0;i
layout.xml

<RelativeLayout android:id="@+id/rel_edit_story"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 android:layout_below="@+id/txt_image"
                 android:padding="10dip"
                 android:layout_margin="10dip"
                 android:background="@drawable/relative_lined_edittext_border">

             <com.rb.lined.edittext.LinedEditText
                android:id="@+id/edit_story"
                android:layout_width="match_parent"
                android:layout_height="match_parent"                
                android:background="@null"
                android:inputType="textMultiLine|textNoSuggestions"
                android:minLines="10"
                android:singleLine="false"
                android:imeOptions="actionNone"
                android:text="Story : " />

             </RelativeLayout>

对于去除红色下划线的标记,您可以像

android:inputType="textNoSuggestions"

对于删除蓝线,这可能会有所帮助

android:background="@null"
范例

   <com.example.lineedittextdemo.LineEditText
    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:singleLine="false"
    android:imeOptions="actionNone"
    android:text="Story : \n" />


请附上代码?已发布,请查看…
所需输出点击此处???为什么没有任何文本?那里有什么好的?我们怎么知道你需要它?谁在画第一幅画中的文字?我看不到这方面的代码。文本“Story:”不包含要求的输出,这是我需要的东西。我的输出还包含默认的蓝色EditText边框,我不需要。谢谢,从你的问题中我得到了我的答案。我使用android:inputType=“textNoSuggestions”还是android:inputType=“textVisiblePassword”我在键盘上没有回车键我在键盘上没有回车键我用的是android:singleLine=“false”。还是没有结果…别管它。。。你能帮我在自定义编辑文本中获得至少10行默认可见的内容吗?这对我有用。您必须使用包裹内容来表示高度,这可能就是它不起作用的原因。放置android:minLines=“10”
   <com.example.lineedittextdemo.LineEditText
    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:singleLine="false"
    android:imeOptions="actionNone"
    android:text="Story : \n" />