{"id":1093,"date":"2024-11-15T08:35:01","date_gmt":"2024-11-15T08:35:01","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=1093"},"modified":"2024-11-15T09:58:20","modified_gmt":"2024-11-15T09:58:20","slug":"kotlintab-navigator","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/11\/15\/kotlintab-navigator\/","title":{"rendered":"[Kotlin]Tab Navigator &#8211; 1.\uba54\uc778\ud654\uba74(Main Screen)"},"content":{"rendered":"\n<p>\ub354 \uce5c\uc808\ud55c \ucf54\ud2c0\ub9b0 \uc571\ud504\ub85c\uadf8\ub798\ubc0d \ucc45\uc5d0 \uc788\ub294 \ucf54\ub4dc \uc785\ub2c8\ub2e4.<br>This is code from the Friendlier Kotlin App Programming book<\/p>\n\n\n\n<p>\uc774 \ucf54\ub4dc\ub294 \ubdf0\ubc14\uc778\ub529\uc744 \uc0ac\uc6a9\ud558\uc9c0 \uc54a\uc558\uc2b5\ub2c8\ub2e4.<br>This code does not use view binding.<\/p>\n\n\n\n<p>Test : compileSdk = 35 targetSdk = 35<\/p>\n\n\n\n<p>1.Directory &amp; files<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"445\" height=\"814\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/11\/directory-1.png\" alt=\"\" class=\"wp-image-1097\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/11\/directory-1.png 445w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/11\/directory-1-164x300.png 164w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><\/figure>\n\n\n\n<p>2.MainActivity.kt<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.example.tabex\n\nimport android.os.Bundle\nimport android.widget.Toast\nimport androidx.activity.enableEdgeToEdge\nimport androidx.appcompat.app.AppCompatActivity\nimport androidx.core.view.ViewCompat\nimport androidx.core.view.WindowInsetsCompat\nimport com.google.android.material.bottomnavigation.BottomNavigationView\n\nclass MainActivity : AppCompatActivity() {\n\n    lateinit var bottom_navigation:BottomNavigationView\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        enableEdgeToEdge()\n        setContentView(R.layout.activity_main)\n        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -&gt;\n            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())\n            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)\n            insets\n        }\n        with(supportFragmentManager.beginTransaction()){\n            val fragment1 = Fragment1()\n            replace(R.id.container,fragment1)\n            commit()\n        }\n        bottom_navigation = findViewById(R.id.bottom_navigation)\n\n       \n        \/\/ \"bottom_navigation..setOnNavigationItemReselectedListener\" was deprecated\n        bottom_navigation.setOnItemSelectedListener {\n            when(it.itemId){\n                R.id.tab1 -&gt; {\n                    showToast(\"\uccab\ubc88\uca30 \ud0ed \uc120\ud0dd\ub428 First tab selected\")\n                    with(supportFragmentManager.beginTransaction()) {\n                        val fragment1 = Fragment1()\n                        replace(R.id.container, fragment1)\n                        commit()\n                    }\n                    return@setOnItemSelectedListener true\n\n                }\n                R.id.tab2 -&gt; {\n                    showToast(\"\ub450\ubc88\uc9f8 \ud0ed \uc120\ud0dd\ub428 Second tab selected\")\n                    with(supportFragmentManager.beginTransaction()) {\n                        val fragment2 = Fragment2()\n                        replace(R.id.container, fragment2)\n                        commit()\n                    }\n                    return@setOnItemSelectedListener true\n                }\n                R.id.tab3 -&gt; {\n                    showToast(\"\uc138\ubc88\uca30 \ud0ed \uc120\ud0dd\ub428 Third tab selected\")\n                    with(supportFragmentManager.beginTransaction()) {\n                        val fragment3 = Fragment3()\n                        replace(R.id.container, fragment3)\n                        commit()\n                    }\n                    return@setOnItemSelectedListener true\n                }\n            }\n            return@setOnItemSelectedListener false\n        }\n    }\n\n    fun showToast(message:String?){\n        Toast.makeText(applicationContext,message,Toast.LENGTH_LONG).show()\n    }\n}<\/code><\/pre>\n\n\n\n<p>3.active_main.xml<\/p>\n\n\n\n<p>-xml design<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"668\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/11\/active_main_xml-2.png\" alt=\"\" class=\"wp-image-1096\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/11\/active_main_xml-2.png 383w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/11\/active_main_xml-2-172x300.png 172w\" sizes=\"auto, (max-width: 383px) 100vw, 383px\" \/><\/figure>\n\n\n\n<p>-xml code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;androidx.drawerlayout.widget.DrawerLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n\n    android:id=\"@+id\/drawerLayout\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:fitsSystemWindows=\"true\"\n    tools:openDrawer=\"start\"&gt;\n    &lt;androidx.coordinatorlayout.widget.CoordinatorLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"&gt;\n\n        &lt;com.google.android.material.appbar.AppBarLayout\n            android:id=\"@+id\/appBarLayout\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"&gt;\n\n            &lt;androidx.appcompat.widget.Toolbar\n                android:id=\"@+id\/toolbar\"\n                android:layout_width=\"match_parent\"\n                android:layout_height=\"match_parent\"\n                android:layout_marginTop=\"30dp\"\n                android:background=\"?attr\/colorPrimary\"\n                app:popupTheme=\"@style\/AppTheme.PopupOverlay\" \/&gt;\n\n        &lt;\/com.google.android.material.appbar.AppBarLayout&gt;\n\n        &lt;FrameLayout\n            android:id=\"@+id\/container\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            app:layout_behavior=\"@string\/appbar_scrolling_view_behavior\"&gt;&lt;\/FrameLayout&gt;\n\n    &lt;\/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;\n\n    &lt;com.google.android.material.navigation.NavigationView\n        android:id=\"@+id\/navigationView\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"match_parent\"\n        android:layout_gravity=\"start\"\n        android:fitsSystemWindows=\"true\"\n        app:headerLayout=\"@layout\/nav_header\"\n        app:menu=\"@menu\/nav_menu\" \/&gt;\n&lt;\/androidx.drawerlayout.widget.DrawerLayout&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ub354 \uce5c\uc808\ud55c \ucf54\ud2c0\ub9b0 \uc571\ud504\ub85c\uadf8\ub798\ubc0d \ucc45\uc5d0 \uc788\ub294 \ucf54\ub4dc \uc785\ub2c8\ub2e4.This is code from the Friendlier Kotlin App Programming book \uc774 \ucf54\ub4dc\ub294 \ubdf0\ubc14\uc778\ub529\uc744 \uc0ac\uc6a9\ud558\uc9c0 \uc54a\uc558\uc2b5\ub2c8\ub2e4.This code does not use view binding. Test : compileSdk = 35 targetSdk = 35 1.Directory &amp; files 2.MainActivity.kt 3.active_main.xml -xml design -xml code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,1],"tags":[],"class_list":["post-1093","post","type-post","status-publish","format-standard","hentry","category-kotlin","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=1093"}],"version-history":[{"count":5,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1093\/revisions"}],"predecessor-version":[{"id":1109,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1093\/revisions\/1109"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}