Android Application
Kotlin 고급 위젯 - 그 밖의 뷰 컨테이너(View Container) : 탭호스트(tabhost)
작성자 임베디드코리아
작성일23-09-24 03:41
조회1,533회
댓글0건
------------------------------------------------------------------------------------
activity_main.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=".MainActivity">
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/th">
<TabWidget
android:id="@android:id/tabs"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:paddingTop="70sp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:textColor="#90C17E"
android:text="들리나요"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab_view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:textColor="#00ACC1"
android:text="가수 : 태 연"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab_view3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:textColor="#0040FF"
android:text=" 작사 : 임보경 \n 작곡 : 이상준" />
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
------------------------------------------------------------------------------------
MainActivity.kt
-------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
private lateinit var tabHost: TabHost
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tabHost = findViewById<TabHost>(R.id.th)
tabHost.setup()
var tabSpecSong = tabHost.newTabSpec("Tab 1").setIndicator("가요곡명")
tabSpecSong.setContent(R.id.tab_view1)
tabHost.addTab(tabSpecSong)
var tabSpecArtist = tabHost.newTabSpec("Tab 2").setIndicator("가수")
tabSpecArtist.setContent(R.id.tab_view2)
tabHost.addTab(tabSpecArtist)
var tabSpecAlbum = tabHost.newTabSpec("Tab 3").setIndicator("작곡")
tabSpecAlbum.setContent(R.id.tab_view3)
tabHost.addTab(tabSpecAlbum)
tabHost.currentTab = 0
}
}