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 ? 现在,我们要前进,我们将与Kotlin开发我们的第一个应用程序 。 这是基本的应用程序,但是它将让您知道程序的结构。

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?

创建新的Kotlin项目后,将在Java和layout文件夹中创建很少的文件。 java文件夹包含kotlin( .kt )文件,而layout文件夹包含.xml文件。 如果您仍然感到困惑,请直接转到上一篇文章,并修改如何创建Kotlin项目 ?

Let's have a look at those files:

让我们看一下这些文件:

MainActivity.kt

MainActivity.kt

package com.onedreamers.myapplication
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
class 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">
<TextView
android: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 26
defaultConfig {
applicationId "com.onedreamers.myapplication"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles 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可以做什么感到惊讶-较短的代码,类型安全的等等。 保持联系。 美好的一天。

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

用Kotlin开发您的第一个应用程序| Android与Kotlin相关推荐

  1. 使用VS Code开发AngularJS 2 第一个应用程序

    使用VS Code开发AngularJS 2 第一个应用程序 目录 运行环境 创建项目 安装依赖包 创建TypeScript应用程序 配置应用程序 运行应用程序 运行环境 运行环境: Windows ...

  2. 使用Eclipse开发Spring的第一个简单程序

    使用Eclipse开发Spring的第一个简单程序 本篇文章将通过一个简单的入门程序向读者演示Spring框架的使用过程,具体如下: 使用Eclipse创建Web应用并导入JAR包 使用Eclipse ...

  3. 用kotlin方式打开《第一行代码:Android》之开发酷欧天气(2)

    参考:<第一行代码:Android>第2版--郭霖 注1:本文为原创,例子可参考郭前辈著作:<第一行代码:Android>第2版 注2:本文不赘述android开发的基本理论, ...

  4. 用kotlin方式打开《第一行代码:Android》之开发酷欧天气(1)

    参考:<第一行代码:Android>第2版--郭霖 注1:本文为原创,例子可参考郭前辈著作:<第一行代码:Android>第2版,转载请注明出处! 注2:本文不赘述androi ...

  5. 初学编程 第一个小程序Android studio实现计算器功能

    源代码下载:https://gitee.com/zha-yingying/calculator.git 1.建立一个新的Layout,我这里使用的是GridLayout(网格布局),提取屏幕宽度(方便 ...

  6. [Android]使用Kotlin开发Android(二)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4829007.html [TOC] 使用Kotlin+OkHtt ...

  7. 安卓重构系列-01使用Kotlin开发第一个Demo

    第一个Kotlin安卓项目 背景 首先,你必须熟练掌握Kotlin这门编程语言,上手难度是不高的,而且真心很好用. 如今,越来越多的安卓项目使用Kotlin开发,现在已经有30%的项目使用Kotlin ...

  8. Kotlin 视频课程系列一:《零基础学习 Kotlin 编程》

    Kotlin 系列课程一:<零基础学习 Kotlin 编程> 课程简介 在你决定要打开这个页面阅读的瞬间,风云巨变互联网行业里拼搏的你, 已经得到了一个引领时代 , 改变命运,突破瓶颈的机 ...

  9. 超越Android:Kotlin在后端的工作方式

    by Adam Arold 亚当·阿罗德(Adam Arold) 超越Android:Kotlin在后端的工作方式 (Going Beyond Android: how Kotlin works on ...

最新文章

  1. 人大经济论坛:统计学的一些经典教材
  2. win10快速运行vue项目跑起来 - 方法篇
  3. 廖雪峰--python教程:笔记四-函数式编程
  4. 使用阿里云服务器(OOS)实现图片上传
  5. C++中cout流的输出顺序
  6. IOS 项目的瘦身工具
  7. bootstrap datetimepicker 初始化及取值
  8. interpeter用python还是pythonw_python-interpreter
  9. 钉钉微应用怎么进入_海目星激光张荣:激光焊接在锂电池生产应用中越来越多...
  10. ad中电容用什么封装_【AD封装】贴片插件晶振(带3D)
  11. 微信自定义分享链接内容,wx.updateAppMessageShareData、wx.updateTimelineShareData、wx.onMenuShareTimeline
  12. 《30天自制操作系统》学习笔记--第12天
  13. ps scavenge java_JVM源码分析(四)Parralel Scavenge 收集器工作流程
  14. SCP批量拷贝指定文件
  15. LabVIEW编程LabVIEW开发如何将十六进制字符转换为ASCII字符
  16. C++ 打开文件夹对话框-OPENFILENAME
  17. 特征图谱字典_空间数据图谱为特征
  18. BitXHub跨链交易的流程
  19. 号角的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  20. 物化视图日志结构与ORA-12034 Mview log younger than last refresh

热门文章

  1. python合并数组输出重复项_python - 不同数组项的所有可能组合[重复] - 堆栈内存溢出...
  2. Android查看web日志,详解Android WebView监听console错误信息
  3. gateway中的局部过滤器_Spring Cloud Gateway中的过滤器工厂:重试过滤器
  4. 有些窗口底部被任务栏挡住了_开始使用 Tint2 吧,一款 Linux 中的开源任务栏
  5. C# 查询一张表的数据用于补充另外一张表的数据 MySQL数据库
  6. NodeJS学习目录
  7. KindEditor编辑器, 利用ajax动态切换编辑器内容
  8. 在vscode使用editorconfig的正确姿势
  9. 织梦dede 5.7系统基本参数无法修改保存,提示Token mismatch!
  10. JavaScript DOM介绍