글 번호: 130 작성자: gihun 작성시간: 2023-10-14 12:57:27.703 조회수: 183

안드로이드 시간때 만든 코드




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.TabSpec tapSpec4 = tabHost.newTabSpec("SEA").setIndicator("바다 사진");
        tapSpec4.setContent(R.id.sea);
        tabHost.addTab(tapSpec4);

        tabHost.setCurrentTab(0);

        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override            public void onTabChanged(String s) {
                Toast.makeText(getApplicationContext(), s + " Tab 이 클릭되었습니다.", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
<?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">


        <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="0dp">

            <ImageView
                    android:id="@+id/home"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/home"/>

            <ImageView
                    android:id="@+id/station"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/station"/>

            <ImageView
                    android:id="@+id/sky"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/sky"/>

            <ImageView
                    android:id="@+id/sea"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/sea" />
        </FrameLayout>

        <TabWidget
                android:id="@android:id/tabs"
                android:background="#FFEB3B"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

    </LinearLayout>
</TabHost>



댓글 리스트

Created by 송바래

✉ gihun3645@naver.com

🚩경기도, 성남시