EditText

EditText

 
  • EditText is used to get input from the user. EditText is commonly used in forms and login or registration screens. Following steps are used to create EditText in Kotlin:
 

Different attributes of EditText widgets –

XML Attributes
Description
android:id
Used to uniquely identify the control
android:gravity
Used to specify how to align the text like left, right, center, top, etc.
android:hint
Used to display the hint text when text is empty
android:text
Used to set the text of the EditText
android:textSize
Used to set size of the text.
android:textColor
Used to set color of the text.
android:textStyle
Used to set style of the text. For example, bold, italic, bolditalic etc.
android:textAllCaps
Used this attribute to show the text in capital letters.
android:width
It makes the TextView be exactly this many pixels wide.
android:height
It makes the TextView be exactly this many pixels tall.
android:maxWidth
Used to make the TextView be at most this many pixels wide.
android:minWidth
Used to make the TextView be at least this many pixels wide.
android:background
Used to set background to this View.
android:backgroundTint
Used to set tint to the background of this view.
android:clickable
Used to set true when you want to make this View clickable. Otherwise, set false.
android:drawableBottom
Used to set drawable to bottom of the text in this view.
android:drawableEnd
Used to set drawable to end of the text in this view.
android:drawableLeft
Used to set drawable to left of the text in this view.
android:drawablePadding
Used to set padding to drawable of the view.
android:drawableRight
Used to set drawable to right of the text in this view.
android:drawableStart
Used to set drawable to start of the text in this view.
android:drawableTop
Used to set drawable to top of the text in this view.
android:elevation
Used to set elevation to this view.
 

Example Edit Text in XML :

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!--EditText with id editText--> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" android:hint="Input" android:inputType="text"/> </LinearLayout>