{"id":778,"date":"2024-08-22T13:22:37","date_gmt":"2024-08-22T13:22:37","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=778"},"modified":"2024-08-22T15:05:24","modified_gmt":"2024-08-22T15:05:24","slug":"kotlin-introduction-to-kotlin-android-app-development","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/08\/22\/kotlin-introduction-to-kotlin-android-app-development\/","title":{"rendered":"[kotlin]\ucf54\ud2c0\ub9b0 \uc548\ub4dc\ub85c\uc774\ub4dc \uc571\uac1c\ubc1c \uc18c\uac1c \/ Introduction to Kotlin Android app development"},"content":{"rendered":"\n<p>\ucf54\ud2c0\ub9b0\uc740 \uc6d0\ub798 \ubc94\uc6a9 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc774\uace0 \uc790\ubc14\uc640 \uc644\ubcbd\ud788 \ud638\ud658\ub429\ub2c8\ub2e4.<br>Kotlin is essentially a general-purpose programming language and is fully compatible with Java.<\/p>\n\n\n\n<p>\uc81c\uac00 \uc18c\uac1c\ud558\uace0\uc790 \ud558\ub294\uac83\uc740 \uc548\ub4dc\ub85c\uc774\ub4dc \uc571 \uac1c\ubc1c\uc5d0 \ub300\ud55c \ub0b4\uc6a9\uc785\ub2c8\ub2e4.<br>What I want to introduce is about Android app development.<\/p>\n\n\n\n<p>\uc548\ub4dc\ub85c\uc774\ub4dc \uc571\uac1c\ubc1c\uc740 \uc790\ubc14\ub85c \uac1c\ubc1c\ud588\uc5c8\uc9c0\ub9cc \uc9c0\uae08\uc740 \uad6c\uae00\uc5d0\uc11c \uc8fc\uc694 \uac1c\ubc1c \uc5b8\uc5b4\ub85c \ucf54\ud2c0\ub9b0\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4<br>Android apps used to be developed in Java, but now Google recommends Kotlin as the main development language.<\/p>\n\n\n\n<p>\uc800\ub3c4 \ucf54\ud2c0\ub9b0\uc740 \uacf5\ubd80 \uc911\uc785\ub2c8\ub2e4.<br>I&#8217;m still studying  Kotlin<\/p>\n\n\n\n<p>\uc774\ubc88 \uc2dc\uac04\uc5d0\ub294 \uac04\ub2e8\ud55c \uc608\uc81c\uc640 \uc18c\uac1c\ub9cc \ud574\ub4dc\ub9bd\ub2c8\ub2e4. <br>This time, I will only provide simple examples and introductions.<\/p>\n\n\n\n<p><strong>1.\uc548\ub4dc\ub85c\uc774\ub4dc \uc2a4\ud29c\ub514\uc624(Android Studio)<\/strong><br>&#8211; \uc544\ub798\ub294 \uc800\uc758 pc\uc5d0 \uc124\uce58\ub41c \uc548\ub4dc\ub85c\uc774\ud2b8 \uc2a4\ud29c\ub514\uc624\uc758 \ubaa8\uc2b5\uc785\ub2c8\ub2e4.<br>Below is a picture of Android Stuido installed on my PC.<\/p>\n\n\n\n<p>&#8211; \uac00\uc6b4\ub370 \ud654\uba74\uc740 \uc571\ub514\uc790\uc778 \ud654\uba74(active_main.xml)\uc774\uace0 \uc6b0\uce21 \uc544\uc774\ucf58\uc788\ub294 \ud654\uba74\uc740 \uc800\uc758 \ubaa8\ubc14\uc77c\ud3f0 \ud654\uba74\uc785\ub2c8\ub2e4.<br>The middle screen is the app design screen, and the screen with the icon on the right is my mobile phone screen.<\/p>\n\n\n\n<p>&#8211; Name Text\uc5d0 \uc785\ub825\ub41c \uac12\uc744 \ubc84\ud2bc \ub204\ub974\uba74 \uacb0\uacfc(\ube68\uac04\uc0c9 \uae00\uc790) \ubd80\ubd84\uc5d0 \ucd9c\ub825\ud558\ub294 \uc608\uc81c \uc785\ub2c8\ub2e4.<br>This is an example of printing the value entered in the Name Text in the results (red text) section when you press the button.<\/p>\n\n\n\n<p>-\uadf8\ub9ac\uace0 \ub2e4\ub978 \ubc84\ud2bc\uc744 \ub204\ub974\uba74 \ud1a0\uc2a4\ud2b8 \uba54\uc138\uc9c0\ub97c \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>And when you press another button, it outputs a toast message.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"541\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/activity_main.xml_-1024x541.png\" alt=\"\" class=\"wp-image-776\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/activity_main.xml_-1024x541.png 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/activity_main.xml_-300x159.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/activity_main.xml_-768x406.png 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/activity_main.xml_-1536x812.png 1536w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/activity_main.xml_.png 1916w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>-\uc544\ub798\ub294 \ucf54\ud2c0\ub9b0 \ucf54\ub4dc \uc785\ub825\ud558\ub294 MainActivity.kt\ud30c\uc77c \ub0b4\uc6a9 \uc785\ub2c8\ub2e4.<br>Below is the contents of the MainActivity.kt file where you enter the Cotlin code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"528\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/code5-1024x528.png\" alt=\"\" class=\"wp-image-796\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/code5-1024x528.png 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/code5-300x155.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/code5-768x396.png 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/code5-1536x792.png 1536w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/code5.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>-\uc608\uc81c \ud504\ub85c\uadf8\ub7a8 \uc2e4\ud589\ud558\uace0 test1\uc744 \uc785\ub825\ud55c\ub4a4 \ubc84\ud2bc\uc744 \ub204\ub978 \uacb0\uacfc \uc785\ub2c8\ub2e4.<br>This is the result of executing the example program, entering test1, and pressing the button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"834\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/test1.png\" alt=\"\" class=\"wp-image-785\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/test1.png 655w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/test1-236x300.png 236w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/figure>\n\n\n\n<p>-\uc544\ub798\ub294 \ub9e8 \uc704\uc758 \ubc84\ud2bc\uc744 \ub204\ub978 \uacb0\uacfc \uc785\ub2c8\ub2e4.(\ud1a0\uc2a4\ud2b8 \uba54\uc138\uc9c0 \uc2e4\ud589)<br>Below is the result of pressing the top button (execute toast message)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"759\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/ToastMessage.png\" alt=\"\" class=\"wp-image-787\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/ToastMessage.png 705w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/ToastMessage-279x300.png 279w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<p><strong>2.kotlin-android-extension<\/strong><br>&#8211; build.gradle.kt\ud30c\uc77c\uc5d0\uc11c kotlin-android-extension\uc740 \ub354 \uc774\uc0c1 \uc0ac\uc6a9\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4.<br>In the build.grade.kt file, kotlin-android-extension is no longer available.<\/p>\n\n\n\n<p>-\uadf8\ub798\uc11c \uadf8\ub0e5 \ubc84\ud2bc,\uc785\ub825\ubc15\uc2a4,\ud14d\uc2a4\ud2b8\ubdf0\ub97c \uc218\ub3d9\uc73c\ub85c \ubd88\ub7ec \uc624\uae30\ud588\uc2b5\ub2c8\ub2e4.<br>So I just manually imported buttons, input box(EditText), and TextView.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        \/\/ \ubc84\ud2bc \ubd88\ub7ec\uc624\uae30\n        \/\/ Import button\n        val button = findViewById&lt;Button&gt;(R.id.button)\n\n        \/\/ \ubc84\ud2bc2 \ubd88\ub7ec\uc624\uae30\n\n        \/\/ Import button\n        val button2 = findViewById&lt;Button&gt;(R.id.button2)\n        \n        \/\/ EditText \ubd88\ub7ec\uc624\uae30\n        \/\/ import EditText\n        val input1 = findViewById&lt;EditText&gt;(R.id.input1)\n\n        \/\/ TextView \ubd88\ub7ec\uc624\uae30\n        \/\/ import TextView\n        val output1 = findViewById&lt;TextView&gt;(R.id.output1)<\/code><\/pre>\n\n\n\n<p><strong>3.\uc804\uccb4 \ucf54\ub4dc(Full Code)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.example.app1\n\nimport android.os.Bundle\nimport android.widget.Button\nimport android.widget.EditText\nimport android.widget.TextView\nimport android.widget.Toast\nimport androidx.activity.enableEdgeToEdge\nimport androidx.appcompat.app.AppCompatActivity\nimport androidx.core.view.ViewCompat\nimport androidx.core.view.WindowInsetsCompat\n\n\/\/import com.example.app1.R.id.button2\n\n\nclass MainActivity : AppCompatActivity() {\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        enableEdgeToEdge()\n        setContentView(R.layout.activity_main)\n\n        \/\/ \ubc84\ud2bc \ubd88\ub7ec\uc624\uae30\n        \/\/ Import button\n        <strong>val button = findViewById&lt;Button&gt;(R.id.button)<\/strong>\n\n        \/\/ \ubc84\ud2bc2 \ubd88\ub7ec\uc624\uae30\n\n        \/\/ Import button\n        <strong>val button2 = findViewById&lt;Button&gt;(R.id.button2)<\/strong>\n        \n        \/\/ EditText \ubd88\ub7ec\uc624\uae30\n        \/\/ import EditText\n        <strong>val input1 = findViewById&lt;EditText&gt;(R.id.input1)<\/strong>\n\n        \/\/ TextView \ubd88\ub7ec\uc624\uae30\n        \/\/ import TextView\n        <strong>val output1 = findViewById&lt;TextView&gt;(R.id.output1)<\/strong>\n\n        \/\/ toast\uba54\uc138\uc9c0 \ub744\uc6b0\uae30\n        \/\/ Running Toast Message\n        button.setOnClickListener(){\n            <strong>Toast.makeText(this@MainActivity,\"show Toast Message\",Toast.LENGTH_SHORT).show()<\/strong>\n        }\n        \/\/ \uc785\ub825\ub41c \ud14d\uc2a4\ud2b8 \uac12 \uac00\uc838\uc640\uc11c \ucd9c\ub825\ud558\uae30\n        \/\/ Get input text values and print them out\n        button2.setOnClickListener(){\n            val inputText1 = input1.text.toString()\n            output1.text = \"\uacb0\uacfc : $inputText1\"\n        }\n        \/\/toast\ubc14\ub85c \uc0ac\uc6a9\ud558\uae30 \n        \/\/Toast.makeText(this@MainActivity, \"Its a toast!\", Toast.LENGTH_SHORT).show()\n\n\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    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ucf54\ud2c0\ub9b0\uc740 \uc6d0\ub798 \ubc94\uc6a9 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc774\uace0 \uc790\ubc14\uc640 \uc644\ubcbd\ud788 \ud638\ud658\ub429\ub2c8\ub2e4.Kotlin is essentially a general-purpose programming language and is fully compatible with Java. \uc81c\uac00 \uc18c\uac1c\ud558\uace0\uc790 \ud558\ub294\uac83\uc740 \uc548\ub4dc\ub85c\uc774\ub4dc \uc571 \uac1c\ubc1c\uc5d0 \ub300\ud55c \ub0b4\uc6a9\uc785\ub2c8\ub2e4.What I want to introduce is about Android app development. \uc548\ub4dc\ub85c\uc774\ub4dc \uc571\uac1c\ubc1c\uc740 \uc790\ubc14\ub85c \uac1c\ubc1c\ud588\uc5c8\uc9c0\ub9cc \uc9c0\uae08\uc740 \uad6c\uae00\uc5d0\uc11c \uc8fc\uc694 \uac1c\ubc1c \uc5b8\uc5b4\ub85c \ucf54\ud2c0\ub9b0\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4Android apps used to be developed in Java, [&hellip;]<\/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-778","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\/778","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=778"}],"version-history":[{"count":11,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/778\/revisions"}],"predecessor-version":[{"id":2587,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/778\/revisions\/2587"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}