Ques. : How to create and display two typical buttons vertically 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"
    android:gravity="center"
    tools:context=".MainActivity">

    <!-- Standard Android Button -->
    <Button
        android:id="@+id/BtnSub1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="25dp"
        android:text="Submit"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textColor="@color/blue"
        android:backgroundTint="@color/red" />

    <!-- AndroidX AppCompat Button -->
    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/BtnSub2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="25dp"
        android:text="Submit"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textColor="@color/blue"
        android:backgroundTint="@color/red" />

</LinearLayout>

NB:
(i) Here, the second Submit button appears in Capital letters because our application's theme can automatically apply all-caps styling to buttons. AppCompatButton can inherit this button styling from the AppCompat/Material theme. To force the second button to display exactly Submit, add - android:textAllCaps="false" this code.
(ii) XML comment line is represented by this symbol <!--     --> but appllied for complete block of statements not for partial lines of code.
(iii) Write the XML codes/program for android design development in 'activity_main.xml' file.
(iv) Remove the comment message completely when execute the program.
Ques. : How to create and display two typical buttons horizontally 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="horizontal"
    android:gravity="center"
    tools:context=".MainActivity">

    <!-- Standard Android Button -->
    <Button
        android:id="@+id/BtnSub1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="05dp"
        android:text="Submit"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textColor="@color/blue"
        android:backgroundTint="@color/red" />

    <!-- AndroidX AppCompat Button -->
    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/BtnSub2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="05dp"
        android:text="Submit"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textAllCaps="false"
        android:textColor="@color/blue"
        android:backgroundTint="@color/red" />

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