日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

用Kotlin开发您的第一个应用程序| Android与Kotlin

發(fā)布時間:2023/12/1 Android 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用Kotlin开发您的第一个应用程序| Android与Kotlin 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

In the previous article, we learned how to setup Kotlin in the android studio? Now moving to journey ahead we are going to develop our first app with Kotlin. It is the basic app, but it will let you know the structure of the program.

在上一篇文章中,我們學習了如何在android studio中設置Kotlin ? 現(xiàn)在,我們要前進,我們將與Kotlin開發(fā)我們的第一個應用程序 。 這是基本的應用程序,但是它將讓您知道程序的結構。

After creating a new Kotlin project, few files will be created in Java and layout folder. The java folder contains the kotlin (.kt) files and layout folder contains the .xml files. If you are still confused, just head over to the previous article and revise how to create a Kotlin project?

創(chuàng)建新的Kotlin項目后,將在Java和layout文件夾中創(chuàng)建很少的文件。 java文件夾包含kotlin( .kt )文件,而layout文件夾包含.xml文件。 如果您仍然感到困惑,請直接轉到上一篇文章,并修改如何創(chuàng)建Kotlin項目 ?

Let's have a look at those files:

讓我們看一下這些文件:

MainActivity.kt

MainActivity.kt

package com.onedreamers.myapplicationimport android.support.v7.app.AppCompatActivity import android.os.Bundleclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)} }

This is kotlin file which contains logics and functionality of our MainActivity.

這是kotlin文件,其中包含我們MainActivity的邏輯和功能。

activity_main.xml

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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"tools:context="com.onedreamers.myapplication.MainActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>

This is layout file which contains code for the design of our activity. Here we have a TextView that will show "Hello world" on the screen. This will remain same either we use java or kotlin as source language.

這是布局文件,其中包含用于設計我們的活動的代碼。 在這里,我們有一個TextView ,它將在屏幕上顯示“ Hello world” 。 我們將使用java或kotlin作為源語言,這將保持不變。

.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

Build.gradle

Build.gradle

apply plugin: 'com.android.application'apply plugin: 'kotlin-android'apply plugin: 'kotlin-android-extensions'android {compileSdkVersion 26defaultConfig {applicationId "com.onedreamers.myapplication"minSdkVersion 21targetSdkVersion 26versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}} }dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"implementation 'com.android.support:appcompat-v7:26.1.0'implementation 'com.android.support.constraint:constraint-layout:1.0.2'implementation 'com.android.support:support-v4:26.1.0'testImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.1'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'}

Output

輸出量

After building the above project, just run it on emulator or any real device. You will see the following result.

構建完上述項目后,只需在模擬器或任何實際設備上運行它即可。 您將看到以下結果。

Conclusion:

結論:

So this article, was just to introduce you to the structure of a kotlin application. Any doubt? feel free to write it down. From the next article, we will know the actual magic of kotlin programming language and kotlin extension for android. You will be amazed of what kotlin can do - shorter code, type-safe and much more. Just stay connected. Good day.

因此,本文只是向您介紹kotlin應用程序的結構 。 任何疑問? 隨時寫下來。 從下一篇文章中,我們將了解kotlin編程語言和適用于android的kotlin擴展的真正魔力。 您將對kotlin可以做什么感到驚訝-較短的代碼,類型安全的等等。 保持聯(lián)系。 美好的一天。

翻譯自: https://www.includehelp.com/kotlin/develop-your-first-app-with-kotlin.aspx

總結

以上是生活随笔為你收集整理的用Kotlin开发您的第一个应用程序| Android与Kotlin的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。