Drawing Multiple Lines in Edittext E.G. Notepad

draw multiple lines on editText

Thank you for everyone who answered. I solved it by replacing the view from the outermost relativeLayout to the inner relativeLayout. Following code is the answer.

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

<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/layouteditbottom"
android:layout_alignParentBottom="true"
android:paddingBottom="18dp"
/>

<RelativeLayout
android:id="@+id/toplayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_alignParentTop="true">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="@string/title"
android:id="@+id/title_text1" />
<EditText android:id="@+id/title"
android:layout_toRightOf="@+id/title_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="18sp"/>
<TextView
android:id="@+id/notelist_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="10sp"
android:textSize="18sp" />
</RelativeLayout>

<view
xmlns:android="http://schemas.android.com/apk/res/android"
class="com.example.note1.NoteEdit$LineEditText"
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layouteditbottom"
android:layout_below="@+id/toplayout"
android:background="@android:color/transparent"
android:capitalize="sentences"
android:fadingEdge="vertical"
android:gravity="top"
android:padding="5dp"
android:scrollbars="vertical"
android:textSize="22sp" />
</RelativeLayout>

EditText with lines like notepad android

For Desabeling Red underline you can put like

android:inputType="textNoSuggestions"

or

android:inputType="textVisiblePassword" 

and for removing blue line this may help.

android:background="@null"

Example

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

Multiline Edittext with Horizontal Lines

Whats your mistake

Your custom class is public class LinedEditText extends EditText

  1. Did you call this in your XML

Just Change your EditText Xml

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

<YOUR_PACKAGE_NAME.LinedEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/edittxt_multilines"
/>

</LinearLayout>

Android add dividers for a multiple line textView

You must use somethink like this link :

  • Drawing multiple lines in edittext e.g. notepad

but this is a link in android developer:

  • http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html

Drawing background lines in an EditText that uses a custom font or typeface

Figured it out. For some reason I had to subtract one from the line height returned from getLineHeight(), no idea why. It works now, here is the complete code for the class:

public class LinedEditText extends EditText {

// the vertical offset scaling factor (10% of the height of the text)
private static final float VERTICAL_OFFSET_SCALING_FACTOR = 0.1f;

// the dashed line scale factors
private static final float DASHED_LINE_ON_SCALE_FACTOR = 0.008f;
private static final float DASHED_LINE_OFF_SCALE_FACTOR = 0.0125f;

// the paint we will use to draw the lines
private Paint dashedLinePaint;

// a reusable rect object
private Rect reuseableRect;

public LinedEditText(Context context) {
super(context);
init();
}

public LinedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public LinedEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

private void init() {

// instantiate the rect
reuseableRect = new Rect();

// instantiate the paint
dashedLinePaint = new Paint();
dashedLinePaint.setARGB(200, 0, 0, 0);
dashedLinePaint.setStyle(Style.STROKE);
}

@Override
protected void onDraw(Canvas canvas) {

// set the path effect based on the view width
dashedLinePaint.setPathEffect(
new DashPathEffect(
new float[]{
getWidth() * DASHED_LINE_ON_SCALE_FACTOR,
getWidth() * DASHED_LINE_OFF_SCALE_FACTOR},
0));

// get the height of the view
int height = getHeight();

// get the height of each line (not subtracting one from the line height makes lines uneven)
int lineHeight = getLineHeight() - 1;

// set the vertical offset basef off of the view width
int verticalOffset = (int) (lineHeight * VERTICAL_OFFSET_SCALING_FACTOR);

// the number of lines equals the height divided by the line height
int numberOfLines = height / lineHeight;

// if there are more lines than what appear on screen
if (getLineCount() > numberOfLines) {

// set the number of lines to the line count
numberOfLines = getLineCount();
}

// get the baseline for the first line
int baseline = getLineBounds(0, reuseableRect);

// for each line
for (int i = 0; i < numberOfLines; i++) {

// draw the line
canvas.drawLine(
reuseableRect.left, // left
baseline + verticalOffset, // top
reuseableRect.right, // right
baseline + verticalOffset, // bottom
dashedLinePaint); // paint instance

// get the baseline for the next line
baseline += lineHeight;
}

super.onDraw(canvas);
}
}

Looking correct now:

correct with new font



Related Topics



Leave a reply



Submit