2017-08-02 6 views
-2

edit text imageWie erreiche ich diese Art von Text bearbeiten mit xml

Ich bin ein absoluter Neuling auf Android. Ich arbeite gerade an einer Notiz-App und ich brauche Hilfe, um diese Art von Textanzeige mit XML zu erreichen. Die Referenzen, die ich bisher gesehen habe, waren mir nicht klar.

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); 
    } 
+0

warum nicht ein Bild verwenden und den Hintergrund des Textes sein bearbeiten erstreckt, dass zeichnbar? – DroiDev

+0

wie komme ich dann mit den mehreren horizontalen Linien? – benruty

+0

Ich dachte, du meintest den oberen Teil .... aber die Unterseite ..... ich würde annehmen, dass es ein Hintergrund ist, der auf Y wiederholt wird – DroiDev

Antwort

0

Erstellen Sie eine Klasse, die eine 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(); 
    } 
} 

In der 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"/> 

enter image description here

+0

wow. hilfreicher Inhalt. Aber wie erreiche ich den Text der obersten Ebene, der wie eine Symbolleiste aussieht? – benruty

+1

ich entwickle nicht Ihre gesamte Ansicht. lernen. – DroiDev

+0

Ich brauche dich nicht, um mir den Code zu zeigen. es ist nur die Idee, die ich wissen muss – benruty

Verwandte Themen