Ques. : How to Create a typical Button 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"
    >

<!-- Used in Old Android Version for Button code-->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:id="@+id/BtnSub"
        android:backgroundTint="@color/red"
        android:text="Submit"
        android:textStyle="bold"
        android:textSize="30sp"
        android:textAllCaps="true"
        android:textColor="@color/blue"
        android:layout_margin="25dp"/>
    

<!-- Used in New Android Version for Button code-->
    <androidx.appcompat.widget.AppCompatButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        
        android:id="@+id/BtnRst"
        android:backgroundTint="@color/red"
        android:text="Submit"
        android:textStyle="bold"
        android:textSize="30sp"
        android:textAllCaps="true"
        android:textColor="@color/blue"
        android:layout_margin="25dp"/>

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

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.