<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/station"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/station"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/sky"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sky"
android:orientation="vertical" />
</FrameLayout>
</LinearLayout>
</TabHost>
package com.example.myapplication;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.Toast;
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tapSpec1 = tabHost.newTabSpec("SKY").setIndicator("하늘 사진");
tapSpec1.setContent(R.id.sky);
tabHost.addTab(tapSpec1);
TabHost.TabSpec tapSpec2 = tabHost.newTabSpec("HOME").setIndicator("집 사진");
tapSpec2.setContent(R.id.home);
tabHost.addTab(tapSpec2);
TabHost.TabSpec tapSpec3 = tabHost.newTabSpec("STATION").setIndicator("정류장 사진");
tapSpec3.setContent(R.id.station);
tabHost.addTab(tapSpec3);
tabHost.setCurrentTab(0);
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String s) {
Toast.makeText(getApplicationContext(), s + " Tab 이 클릭되었습니다.", Toast.LENGTH_SHORT).show();
}
});
}
}
Created by 송바래
✉ gihun3645@naver.com
🚩경기도, 성남시