반응형

[Gradle 설정]

1
id 'kotlin-android-extensions'
cs

<MainActivity>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.example.myapplication
 
import android.app.TabActivity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.MultiAutoCompleteTextView
import kotlinx.android.synthetic.main.activity_main.*
 
@Suppress("deprecation")
class MainActivity : TabActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
 
        var tabHost = this.tabHost
 
        var tabSpecDog = tabHost.newTabSpec("DOG").setIndicator("강아지")
        tabSpecDog.setContent(R.id.tabDog)
        tabHost.addTab(tabSpecDog)
 
        var tabSpecCat = tabHost.newTabSpec("CAT").setIndicator("고양이")
        tabSpecCat.setContent(R.id.tabCat)
        tabHost.addTab(tabSpecCat)
 
        var tabSpecRabbit = tabHost.newTabSpec("RABBIT").setIndicator("토끼")
        tabSpecRabbit.setContent(R.id.tabRabbit)
        tabHost.addTab(tabSpecRabbit)
 
        var tabSpecHorse = tabHost.newTabSpec("HORSE").setIndicator("말")
        tabSpecHorse.setContent(R.id.tabHorse)
        tabHost.addTab(tabSpecHorse)
 
        tabHost.currentTab = 0
    }
}
cs

 

<activity_main.xml>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/tabhost"
    android:orientation="vertical">
 
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
 
 
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@android:id/tabcontent">
 
            <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dog"
                android:id="@+id/tabDog"/>
 
            <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/cat"
                android:id="@+id/tabCat"/>
 
            <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/rabbit"
                android:id="@+id/tabRabbit"/>
 
            <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/horse"
                android:id="@+id/tabHorse"/>
        </FrameLayout>
 
        <TabWidget
            android:background="#ffff00"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@android:id/tabs"/>
 
    </LinearLayout>
 
 
</TabHost>
cs

 

반응형

+ Recent posts