简评:原作者是 Basecamp 的一位 Android 工程师,而 Basecamp 的 Android App 已经 100% 的使用 Kotlin 来开发了,相信他们的建议应该是非常有用的。 Extension functions 是Kotlin 的一个重要特性,让你无需继承一个类就拓展其功能。在 Basecamp,他们就利用了这一特性来简化了某些常用的 Androi
Android Studio 3.0的一个亮点就是内置了 Kotlin 的支持(https://developer.android.google.cn/kotlin/index.html)。正如 Google I/O 2017 所说的那样, Kotlin 已成为 Android 官方开发语言。 使用Android Studio 3.0, 我们可以方便地把Java 源代码自动转换成 Kotlin 代码,也可以直接创建 Kotlin 语言开发的 Android...
apply plugin: 'kotlin-android-extensions' 1. 2.2、导入合成属性 **在 Activity中: ** 按照import kotlinx.android.synthetic.main.<布局>.*格式,可以导入布局文件中所有控件属性。 **在 View 中(Adapter , Fragment等) 中: ** 按照import kotlinx.android.synthetic.main.<布局>.view.*格式,可以导入布局文...
表示该类位于 package="com.easy.kotlin" 路径下。<activity android:name=".ItemListActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category....
import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity(), View.OnClickListener { val CUSTOM_PREF_NAME = "User_data" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ...
API请求:Java 与 Kotlin对比 我总喜欢把这两种语言进行对比,看看坚持使用Java我们会错过什么。从URL恢复JSON的典型代码是这样: 1try{2URL url =newURL("<api call>");34urlConnection =(HttpURLConnection) url.openConnection();5urlConnection.setRequestMethod("GET");6urlConnection.connect();78InputStream ...
在项目中配置Kotlin选项对项目的build.gradle文件进行了许多调整,因此让我们仔细看一下这些文件的更改方式。 打开您的项目级别的build.gradle文件-它应如下所示: buildscript { //Declares the version of Kotlin that you’re using. You’ll notice that the version of Kotlin is mentioned in both the buildscri...
官方文档中提到要使用自定义的协程作用域,当然,Kotlin 已经给我们提供了合适的协程作用域 MainScope 。看一下 MainScope 的定义: 复制 publicfun MainScope(): CoroutineScope = ContextScope(SupervisorJob() + Dispatchers.Main) 1. 记着这个定义,在后面 ViewModel 的协程使用中也会借鉴这种写法。
Kotlin也是基于JVM设计的编程语言,算是对Java的温和改良,她是一个开源项目的成果,拥有很高的声望,很多公司、组织、业界大犇都很喜欢她,Square公司的Jake大神(Dagger、ButterKnife、Retrofit、OkHttp...之父)就专门写了篇Using Project Kotlin for Android为Kotlin站台。
This is the repository for the Now in Android app. It is a work in progress 🚧. Now in Android is a fully functional Android app built entirely with Kotlin and Jetpack Compose. It follows Android design and development best practices and is intended to be a useful reference for developers...