Ques. : How to create two default input text boxes to accept certain text or numbers, or both input values, from users in Android using XML code in the LinearLayout view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/app_name"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="15"
        android:inputType="text"
        android:hint="Enter your first text/numeric value here"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="15"
        android:inputType="text"
        android:hint="Enter your second text/numeric value here"/>
</LinearLayout>
Ques. : How to create two default input text boxes to accept only numeric input values from users in Android using XML code in the LinearLayout view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/app_name"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="15"
        android:inputType="number"
        android:hint="Enter your first text/numeric value here"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="15"
        android:inputType="number"
        android:hint="Enter your second text/numeric value here"/>
</LinearLayout>
Ques. : How do we create two customized (fully solid rectangular outline/border) input text boxes with the cursor in the first EditText box in Android using XML in a LinearLayout to accept only numeric input from users?

First create an 'xml' file in 'drawable' resource file(path= app → res → drawable → Right-click → New → Drawable Resource File - put file name 'edittext_border' - ok- open the file in Code window form(not in Design window form) - remove all the previous default codes and paste the new given codes) with following codes :- 

edittext_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- Background -->
    <solid android:color="#FFFFFF" />

    <!-- Complete border -->
    <stroke
        android:width="2dp"
        android:color="#000000" />

    <!-- Space inside textbox -->
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp" />

    <!-- Slightly rounded corners -->
    <corners android:radius="4dp" />

</shape>


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:inputType="number"
        android:hint="Enter your first numeric value here"
        android:background="@drawable/edittext_border"
        android:padding="10dp" />

        <requestFocus/>


    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_marginTop="15dp"
        android:inputType="number"
        android:hint="Enter your second numeric value here"
        android:background="@drawable/edittext_border"
        android:padding="10dp" />

</LinearLayout>

Loading

Categories: Android

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.