Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用xml实现这种类型的编辑文本_Java_Android - Fatal编程技术网

Java 如何使用xml实现这种类型的编辑文本

Java 如何使用xml实现这种类型的编辑文本,java,android,Java,Android,我是一个完全的android新手。我目前正在开发一个Notes应用程序,我需要帮助实现这种使用xml的编辑文本视图。到目前为止,我看到的参考资料对我来说并不清楚 protected void onDraw(Canvas canvas) { // Gets the number of lines of text in the View. int count = getLineCount(); // Gets the global Rect an

我是一个完全的android新手。我目前正在开发一个Notes应用程序,我需要帮助实现这种使用xml的编辑文本视图。到目前为止,我看到的参考资料对我来说并不清楚

 protected void onDraw(Canvas canvas) {

        // Gets the number of lines of text in the View.
        int count = getLineCount();

        // Gets the global Rect and Paint objects
        Rect r = mRect;
        Paint paint = mPaint;

        /*
         * Draws one line in the rectangle for every line of text in the EditText
         */
        for (int i = 0; i < count; i++) {

            // Gets the baseline coordinates for the current line of text
            int baseline = getLineBounds(i, r);

            /*
             * Draws a line in the background from the left of the rectangle to the right,
             * at a vertical position one dip below the baseline, using the "paint" object
             * for details.
             */
            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
        }

        // Finishes up by calling the parent method
        super.onDraw(canvas);
    }
受保护的void onDraw(画布){
//获取视图中的文本行数。
int count=getLineCount();
//获取全局Rect和Paint对象
Rect r=mRect;
油漆油漆=mPaint;
/*
*为EditText中的每行文本在矩形中绘制一行
*/
for(int i=0;i
创建一个扩展EditText的类

public class LinedEditText extends EditText {
    private Rect mRect;
    private Paint mPaint;

    public LinedEditText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(0xFF000000); //change this to your color
    }

    /**
     * This is called to draw the LinedEditText object
     * @param canvas The canvas on which the background is drawn.
     */
    @Override
    protected void onDraw(Canvas canvas)
    {
        int height = canvas.getHeight();
        int curHeight = 0;
        Rect r = mRect;
        Paint paint = mPaint;
        int baseline = getLineBounds(0, r);
        for (curHeight = baseline + 1; curHeight < height;
             curHeight += getLineHeight())
        {
            canvas.drawLine(r.left, curHeight, r.right, curHeight, paint);
        }
        super.onDraw(canvas);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec,heightMeasureSpec);
        invalidate();
    }
}
公共类LinedEditText扩展了EditText{
私人直肠;
私人油漆;
public LinedEditText(上下文、属性集属性)
{
超级(上下文,attrs);
mRect=新的Rect();
mPaint=新油漆();
mPaint.setStyle(油漆、样式、笔划);
mPaint.setColor(0xFF000000);//将其更改为您的颜色
}
/**
*调用此函数以绘制LinedItemText对象
*@param canvas绘制背景的画布。
*/
@凌驾
受保护的void onDraw(画布)
{
int height=canvas.getHeight();
int curHeight=0;
Rect r=mRect;
油漆油漆=mPaint;
int基线=getLineBounds(0,r);
对于(curHeight=baseline+1;curHeight
在XML中

<your.package.name.LinedEditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top"
    android:layout_margin="10dp"
    android:background="@null"
    android:inputType="textMultiLine|textNoSuggestions"
    android:minLines="10"
    android:singleLine="false"
    android:imeOptions="actionNone"/>


为什么不使用图像并使编辑文本的背景具有可绘制性?那么我该如何绘制多条水平线?我以为你指的是顶部。。。。但是底部。。。。。我不得不假设这是一个在YOW上重复的背景。有用的内容。但是我如何实现像工具栏一样的顶级编辑文本呢?我不需要你给我看代码。这正是我需要知道的想法如果你有xml方面的经验,我认为这很容易做到…创建一个相对布局,在相对布局的内部,放置退出文本和图像。。。