WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

XML Android



XML in Android

XML define as Extensible Markup Language. XML is very easy language.

XML for designing our layouts in Android.

In this tutorial we learn about basic XML android.


Basics Of User Interface(UI)

UI have using the hierarchy of View and ViewGroup objects.

ViewGroup Divide three categorizes

  • ViewGroup(Linear Layout)
  • View(Button)
  • View(TextView)
    • Relative Layout categorizes

      • EditText

      Example XML in Android

      Here a simple example of XML in android we an put this code in activity_main.xml


      activity_main.xml:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical" android:layout_width="match_parent"
       android:layout_height="match_parent">
      
      
       <Button
       android:id="@+id/buton2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Button"/>
      
       <TextView
       android:id="@+id/textView2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Edit text"
       android:layout_marginTop="144dp"
       android:textSize="55dp"/>
      
       <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">
      
       <EditText
       android:id="@+id/editTextName"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:hint="Field name1"
       />
      
      
      
       </RelativeLayout>
      </LinearLayout>

      Output

      XML with example

      Why XML Used In Android?

      We can use XML files used for different purposes.

      XML used in android is listed follow as:

      • Strings XML File(strings.xml): This is mainly used to replace the Hard-coded strings with a single string.
      • Strings XML File Example

        <resources>
        <string name="app_name">Create First App
        
        <string name="hello_world">Hello Android!
        <string name="action_settings">Settings
        <string name="username">User Name
        <!-- define your strings here -->
        </resources>
        
        
        Strings XML File Exmple1
      • Styles XML File(styles.xml)This is used to Change the styles and theme for the UI(User Interface) of APP. Or By using it we can change Responsive theme

        Styles XML File Example

        styles XML File follow as:

        <resources>
        
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        </style>
        
        
        
        
        Strings XML File Exmple1
      • Layout XML This is similar to TextView, Button and other UI elements.

        This is the main part of UI.

        Layout XML Example

        Layout XML follow as:
        <?xml version="1.0" encoding="utf-8"?>
        <android.support.constraint.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:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity">
        
            <Button
                android:id="@+id/buton5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"/>
        
          <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="sample Text"
                android:layout_marginTop="144dp"
                android:textSize="55dp"/>
        
        
           <EditText
                android:id="@+id/welookups"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="welookups"
                tools:layout_editor_absoluteX="0dp"
                tools:layout_editor_absoluteY="16dp" />
        
        </android.support.constraint.ConstraintLayout>
        
        Layout XML1
      • Manifest XML (Mainfest.xml)It is used to full control componants of APPS/GAMES. It have many application packages, Activities, receivers, services and the permissions that who wants to application need
      • Manifest XML Example

        Manifest follow as:

        
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.example.admin.welookups">
           <uses-permission android:name="android.permission.INTERNET" />
           <uses-permission android:name="android.permission.CAMERA" />
           <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        
        
           <application
                android:allowBackup="true"
                android:icon="@mipmap/ic_launcher"
                android:label="@string/app_name"
                android:roundIcon="@mipmap/ic_launcher_round"
                android:supportsRtl="true"
                android:theme="@style/AppTheme">
           <activity android:name=".MainActivity">
                 <intent-filter>
                      <action android:name="android.intent.action.MAIN" />
        
                    <category android:name="android.intent.category.LAUNCHER" />
                   </intent-filter>
               </activity>
            </application>
        
        </manifest>
        
        
          Color XML (colors.xml) This is used to Change the color codes that we want to need to our apps.

        Color XML Example

        <?xml version="1.0" encoding="utf-8"?>
        <resources>
        <!-- define your colors Here -->
        <color name="pink">#C870E6
        <color name="white">#fff
        </resources>