![]() |
In Android Jetpack Compose, a TextField is used to take input from the user in the form of text. TextField when in focus or when clicked invokes a keypad which is technically termed a Keyboard or a Soft-Keyboard. Soft-Keyboard in general consists of all characters that include numbers, alphabets, special characters, emoticons, and space. However, one or more of these types may not be needed as input and so, the specifications of the Soft-Keyboard may need to be changed. In the below image, you will find many types of inputs that a Soft-Keyboard can be restricted to like Password, Number, Ascii, Email, NumberPassword, Phone, Text, and Uri. ![]()
So in this article, we will show you how you could set Text Field Input Type to Number in Android using Jetpack Compose. Follow the below steps once the IDE is ready. Step by Step ImplementationStep 1: Create a New Project in Android Studio To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Step 2: Working with the MainActivity.kt file Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail. Kotlin
Output: In the below image, you can see that TextField takes only numbers as input. ![]()
|
Reffered: https://www.geeksforgeeks.org
Android |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |