‫Welcome back.
‫In this video we're going to learn about Edit Text in Android.
‫And Edit Text is a user interface widget that provides a text input field for users to enter text.
‫It allows users to input textual information such as their name, email address, or other information.
‫Edit text is a fundamental component in building forms, search bars, chat interfaces, and various
‫other features in Android applications.
‫To create and edit text, we start with edit text tag, or you can simply go to the design mode and
‫here you need to search for edit text, plain text, password or whatever you want.
‫The type of this edit text so you can drag and drop a password.
‫You can drag and drop an email, edit text, a number, plain text.
‫So this depends on the data that you want to collect from the user.
‫I go to the split mode and continue with the edit text.
‫Here I specify the width as Matchparent and wrapcontent for the height.
‫Here we go.
‫You created your first edit text.
‫I'll drag and drop it below this text view, and here I'll click on this Infer Constraints button.
‫Also, I'll use this to infer the constraints in order to prevent any error.
‫Later on, we'll talk about Constraintlayout in deep details and we'll learn about these constraints.
‫But let me focus on this edit text.
‫By the way these are the attributes for the constraint layout.
‫Don't worry, I'll explain them later on.
‫Then we need to specify an edit text ID attribute.
‫As I told you, the ID assigns a unique ID or a unique identifier to the edit text, which you can use
‫to reference it in your Kotlin code.
‫This is the edit text.
‫I'll name it as my edit text.
‫Also, you can specify many other attributes for this.
‫Edit text width and height.
‫These attributes determine the width and height of the edit text.
‫You can specify Wrapcontent Matchparent or you can specify numbers.
‫For example, the width should be 200 dpi.
‫You can see the width is shrinking down.
‫I use Wrapcontent when you set a views width for or height to wrapcontent, it means that the view will
‫size itself based on the content it holds.
‫The view will expand or shrink to fit the content it contains, and if you set the width or the height
‫to match parent, you are telling that the view will take up all the available space in its parent container.
‫It stretches to fill the parent's width or height.
‫In this case, I'm stretching the width to fill the parent, and I'm shrinking the size of the height
‫to wrap the content of this edit text.
‫Also, you can define many attributes to this edit text.
‫You can specify the input type.
‫This attribute specifies the type of input allowed in the edit text.
‫Common values include text, text, email, address, number, phone, and more.
‫It controls the keyboard layout and input validation.
‫For example, if you select phone, you can't add letters, only numbers are allowed.
‫Also, we can use max length attribute sets the maximum number of characters the user can enter into
‫the edit text.
‫I'll set it to 30 no more than 30 numbers because I specify the type as phone.
‫Also, you can display a hint for the user.
‫Please enter your phone number.
‫You can see it in the layout.
‫It will appear as a hint you can control the text color.
‫For example, you can select as black.
‫Also you can control the size 32 SP.
‫You can see the height of this edit text is increased.
‫Moreover, you can add a background attribute.
‫This attribute allows you to set the background of the edit text, either a color drawable or a shape.
‫I'll use for example black.
‫You can see it and if I select for example white.
‫Also you can control the hint color text color I'll make it as white.
‫You can see.
‫Please enter your phone number if you click on this.
‫Edit text, this hint will disappear.
‫Now let's move to the main activity and initialize this edit text the same way as we done before.
‫Late initiate var my edit text.
‫It's of type edit text and in the Oncreate method under the Setcontentview I need to initialize my edit
‫text equals to Findviewbyid r.id dot my edit text.
‫Moreover, you can use my edit text variable with many functions that are included in this class to
‫get the entered text.
‫It's very simple.
‫You can use the text attribute which is get text from the edit text dot two string, and you can store
‫it inside a variable.
‫Val entered text, for example, equals to my edit text dot to string and using the text attribute text
‫refers to the get text from edit text class.
‫This is a basic example of how to use an edit text in an Android Kotlin application.
‫You can further enhance it by implementing input validation, error handling, and other features to
‫meet your specific requirements.