TabHost


TabHost
************************** main.xml *********************
<?xml version="1.0" encoding="utf-8"?>
<TabHost 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:id="@android:id/tabhost"
    tools:context=".MainActivity">

<AbsoluteLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/tabcontent"/>
    <TabWidget
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@android:id/tabs"/>

</AbsoluteLayout>

</TabHost>

************************** LoginIactivity.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".login">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:text="Email ID"/>
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:hint="Enetr Your Email "/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="PASSWORD"/>
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pass"
        android:inputType="numberPassword"
        android:hint="Password"/>

</LinearLayout>

**************************** Registration_Activity.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".registration">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:text="Registration"/>

</LinearLayout>


********************************** Main.java *************************
package com.example.tabview;

import androidx.appcompat.app.AppCompatActivity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class MainActivity extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TabHost host=getTabHost();
        host.addTab(host.newTabSpec("tab1").setIndicator("LOGIN").setContent(new Intent(this,login.class)));
        host.addTab(host.newTabSpec("tab2").setIndicator("REGISTRATION").setContent(new Intent(this,registration.class)));
   host.setCurrentTab(0);
    }
}
******************************* Login .java ********************************
package com.example.tabview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class login extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }
}
********************************** Registration.java**************************

package com.example.tabview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class registration extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);
    }
}





0 Comments