How to create an EditText (optional), what would it be on the whole screen and with such lines?

Example:

enter image description here

PS When using the code in the answer Likhanov'a turns out like this: enter image description here

The code is slightly modified:

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.x.myfirstnormal.ActivityAdd" android:background="#D6E100"> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginTop="2dp" android:ems="10" android:hint="Name" android:inputType="textPersonName" android:backgroundTint="@android:color/black" android:textColor="@android:color/black" android:textColorHint="@android:color/black" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="32dp" android:layout_marginTop="52dp" android:text="Name*" android:textColor="@android:color/black" android:textSize="20sp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/button6" android:layout_width="120dp" android:layout_height="50dp" android:layout_marginBottom="552dp" android:layout_marginLeft="168dp" android:backgroundTint="@android:color/holo_green_light" android:text="OK" android:textColor="@android:color/background_light" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" /> <Button android:id="@+id/button7" android:layout_width="120dp" android:layout_height="52dp" android:layout_marginBottom="552dp" android:backgroundTint="@android:color/holo_red_light" android:text="Clear all" android:textColor="@android:color/background_light" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" /> <EditText android:id="@+id/editText6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:ems="10" android:hint="Female" android:inputType="textPersonName" android:backgroundTint="@android:color/black" android:textColor="@android:color/black" android:textColorHint="@android:color/black" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/female" /> <TextView android:id="@+id/female" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="32dp" android:text="Female*" android:textColor="@android:color/black" android:textSize="20sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/editText" android:layout_marginLeft="32dp" /> <!--<ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" tools:layout_editor_absoluteX="147dp" tools:layout_editor_absoluteY="228dp"> --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="240dp" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"> <com.example.x.myfirstnormal.LinedEditText android:id="@+id/mainEditText" android:layout_width="match_parent" android:layout_height="match_parent" android:inputType="textMultiLine" android:ems="10" android:textColor="@color/Black" /> </LinearLayout> <!--</ScrollView>--> </android.support.constraint.ConstraintLayout> 
  • one
    @pavlofff Changed the question. - True-hacker

1 answer 1

 <EditText android:inputType="textMultiLine" android:lines="8" <!-- ΠΏΡ€ΠΈΠΎΡ€ΠΈΡ‚Π΅Ρ‚Π½ΠΎΠ΅ ΠΊΠΎΠ»-Π²ΠΎ Π»ΠΈΠ½ΠΈΠΉ для отобраТСния --> android:minLines="6" <!-- ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ Π»ΠΈΠ½ΠΈΠΉ --> android:gravity="top|left" <!-- позиция курсора --> android:maxLines="10" <!-- максимум Π»ΠΈΠ½ΠΈΠΉ --> android:layout_height="match_parent" android:layout_width="match_parent" android:scrollbars="vertical" /> 

If you need lines in EditText you need to create your custom EditText . Example.

Create a class

 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(getResources().getColor()); //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); } } 

And such an xml file

 <?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> 

An example of what happened

An example of what happened A source

  • 2
    And how do you know the same lines? - True-hacker
  • 3
    and then what happened? Same in terms of style? - Likhanov
  • 2
    It turned out a text field, without lines, just a text field. - True-hacker
  • 3
    It seems this is only possible by creating your custom editText - Likhanov
  • four
    @ True-hacker unfortunately I do not know why you have it. I attached my screen to the answer - Likhanov