Ques. : How to display a normal “Hello World” message in Android using XML code in Linear Layout Views?
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/app_name"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        
        android:id="@+id/TxtVwVal"
        android:text="Hello world"      <!-- Hard Coded String message -->
        android:text="@string/msg"      <!-- Soft Coded Real String message -->
        android:justificationMode="inter_word"

        android:textSize="35sp"     <!-- sp means scalable pixel for font size and dp means density pixel for form size, space etc. -->
        android:textStyle="bold"
        android:textColor="@color/red"/>

</LinearLayout>

NB: 
(i) XML comment line is represented by this symbol <!--     --> but appllied for complete block of statements not for partial lines of code.
(ii) Write the XML codes/program for android design development in 'activity_main.xml' file.
(iii) Remove the comment message completely when execute the program.
(iv) Code should be written in activity_main.xml file
Ques. : How to display the message “Hello World”, “Hello India”, and “Hello Bihar” in the next lines in Android using XML code in the Constraint Layout View?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!\nHello India!\nHello Bihar"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Output:
Hello World
Hello India
Hello Bihar 

NB: 
android:text="Hello World!"
android:text="Hello India!"
android:text="Hello Bihar!"

We can not use like this in single TextView of the XML code to obtained above output because -

Only the last value (android:text="Hello Bihar!") will be used by Android Studio.
The previous android:text values ("Hello World!" and "Hello India!") will be ignored. 
To display all three messages in a single TextView in next line, we should combine them into one string, using \n for new lines OR we can use in three different TextView each.
Ques. : How to display the message “Hello World” in All Capital Letters in Android using XML code in the Linear Layout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/app_name"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        
        android:text="Hello world"
        android:textSize="35sp"
        android:textStyle="bold"
        android:textAllCaps="true"
        android:textColor="@color/design_default_color_on_secondary"/>

</LinearLayout>
Ques. : How to display the Input Text box to take certain input values from users in Android using XML code in the Linear Layout 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: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"   <!--ems represents the width size of input box as multiple of largest letter M of English alphabets i.e., 15 M size-->

        android:inputType="text"
        android:inputType="number"

        android:hint="Enter your text/numeric value here"
        android:hint="@string/ph"
        />

</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.