TapHost : 탭호스트 화면전환
2019. 3. 19. 15:23ㆍAndriod
#1 *.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout1"
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">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tabSong"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00000"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="@+id/tabArtist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f000"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:id="@+id/tabAlbum"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00fff"
android:orientation="horizontal">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
#2 *.java
package com.example.a0319_02;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity{ // 상속이 TabActivity이다. 주의할 것!
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpecSong = tabHost.newTabSpec("SONG").setIndicator("음악별");
tabSpecSong.setContent(R.id.tabSong);
tabHost.addTab(tabSpecSong);
TabHost.TabSpec tabSpecArtist = tabHost.newTabSpec("ARTIST").setIndicator("가수별");
tabSpecArtist.setContent(R.id.tabArtist);
tabHost.addTab(tabSpecArtist);
TabHost.TabSpec tabSpecAlbum = tabHost.newTabSpec("ALBUM").setIndicator("앨범별");
tabSpecAlbum.setContent(R.id.tabAlbum);
tabHost.addTab(tabSpecAlbum);
tabHost.setCurrentTab(0);
}
}
'Andriod' 카테고리의 다른 글
예제: RadioButton,CheckBoxm,ImageView,Spinner (0) | 2019.04.08 |
---|---|
간단한 브라우저 만들기 (0) | 2019.03.19 |
Bar :ProgressBar,SeekBar,RatingBar (0) | 2019.03.19 |
ViewFlipper : 화면 전환 (0) | 2019.03.19 |
자동완성텍스트뷰,멀티자동완성테스트뷰 (0) | 2019.03.19 |