anko

Create a custom View/ViewGroup class in Anko DSL

冷暖自知 提交于 2019-12-03 12:02:38
问题 I want to create a custom View which is just a wrapper of some Android Views. I looked into creating a custom ViewGroup which manages the layout of it's child views, but I don't need such complexity. What I basically want to do is something like: class MainActivity verticalLayout { textView { text = "Something that comes above the swipe" } swipeLayout { } } class SwipeLayout linearLayout { textView { text = "Some text" } textView { text = "Another text" } } The reason is that I'd like to move

Can't get dokka to generate kotlin docs on gradle/android project

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm following the gradle plugin section in https://github.com/Kotlin/dokka . I also tried the dokka-gradle-example example in https://github.com/JetBrains/kotlin-examples/tree/master/gradle/dokka-gradle-example . The versions I'm using are: android: '23.1.1' dokka: '0.9.6' gradle-android-plugin: '1.5.0' kotlin: '1.0.0-rc-1036' but I also tried with Dokka versions from 0.9 up to 0.9.7. The relevant parts of the output are: ... :app:dokka FAILED :app:dokka (Thread[Daemon worker Thread 9,5,main]) completed. Took 0.766 secs. FAILURE: Build

Create a custom View/ViewGroup class in Anko DSL

主宰稳场 提交于 2019-12-03 02:30:40
I want to create a custom View which is just a wrapper of some Android Views. I looked into creating a custom ViewGroup which manages the layout of it's child views, but I don't need such complexity. What I basically want to do is something like: class MainActivity verticalLayout { textView { text = "Something that comes above the swipe" } swipeLayout { } } class SwipeLayout linearLayout { textView { text = "Some text" } textView { text = "Another text" } } The reason is that I'd like to move the SwipeLayout code into a separate file but don't want to do any complex layout stuff myself. Is

为什么 Android 开发者都应该尝试一下 Anko?

旧城冷巷雨未停 提交于 2019-12-01 19:13:43
简评: 这里介绍的仅仅是 Anko 中很小的一部分,Kotlin + Anko 真的让 Android 开发简化了不少,用了 Anko 基本就可以告别那些什么 Android 不得不知的代码收集贴了。 Anko 是 JetBrains 针对 Kotlin 推出的 Android 开发库,其目的是通过 Kotlin 让 Android 开发更加简单。 Anko 主要有四个模块: Commons Layouts SQLite Coroutines 在这篇文章中,我们先主要介绍其 Commons 模块中的一些内容: 首先,View.setOnClickListener 方法可以说是广大 Android 开发者写得最多的方法之一了,如果你是用 Kotlin,那么代码看起来应该是类似这样的: button.setOnClickListener(object : View.OnClickListener{ override fun onClick(v: View) { } }) 通过使用 Anko 可以把代码缩减为: button.onClick { } Intent 当我们希望跳转到新的 Activity 时,代码类似这样: val intent = Intent(this, MainActivity::class.java) intent.putExtra("id", 5) intent

【Kotlin For Android】(三): Anko 库

北城余情 提交于 2019-11-30 14:59:42
一、简介 Github地址 Anko 是一个使 Android应用程序 开发更快,更容易的库。它使你的代码变得简洁易读,并让您忘记 Android SDK for Java 的粗糙边缘。 Anko 由几部分组成: Anko Commons :一个轻量级的库,里面充满了 intents ,对话框,日志等帮助器; Anko Layouts :用于编写动态Android布局 的快速且类型安全的方法; Anko SQLite:查询适用于 Android SQLite的 DS L和分析器集合; Anko Coroutines:基于 kotlinx.coroutines 库的实用程序。 1.1、Anko Commons Anko Commons 是 Kotlin Android 开发人员的“工具箱”。该库包含很多 Android SDK助手 ,包括但不限于: Intents ( wiki ); Dialogs and toasts ( wiki ); Logging ( wiki ); Resources and dimensions ( wiki ). 1.2、Anko Layouts ( wiki ) _Anko Layouts_是用于编写动态Android布局的DSL。这是一个用Anko DSL编写的简单用户界面: verticalLayout { val name = editText

写给Android开发者的Kotlin入门

只愿长相守 提交于 2019-11-29 14:02:54
写给Android开发者的Kotlin入门 Google在今年的IO大会上宣布,将Android开发的官方语言更换为Kotlin,作为跟着Google玩儿Android的人,我们必须尽快了解和使用Kotlin语言。 不过Kotlin毕竟是语言级别的新事物,比起Java来说,从编程思想到代码细节都有不少变化,我们最好先对Kotlin有个整体的基本的了解,然后再去学习和使用,这样才能高效地掌握Kotlin语言。 Java的辉煌与阴影 1995年,当年如日中天的Sun公司发布了Java语言,引起了巨大的轰动,与当时主流的C语言和Basic语言比起来,Java语言简单、面向对象、稳定、与平台无关、解释型、多线程、动态等特点,就像是打开了一个新的世界,一时间风靡全球,云集者众,微软为了模仿Java搞出C#语言,Netscape为了赶时髦硬塞出一个JavaScript语言,IBM则捏着鼻子做了Java IDE Eclipse(日蚀,呵呵)。直到现在,Java在编程世界里还占据着举足轻重的地位,Andy Rubin在开发Android系统时,也很自然地采用了Java和C++(C++负责NDK开发)作为开发语言。 但是,Java毕竟是20多年前的语言了,虽然有不断扩展更新,但是底层设计思想是很难改动的,这就导致它很难实现一些新的语言特性,例如函数式编程、Lambda 表达式、流式API、高阶函数

How to create Kotlin DSL - DSL syntax Kotlin

送分小仙女□ 提交于 2019-11-26 20:57:55
问题 As with anko you can write callback functions like this: alert { title = "" message = "" yesButton { toast("Yes") } noButton { toast("No") } } How can I create a nested functions like that? I tried creating it like below but doesn't seem to be working. class Test { fun f1(function: () -> Unit) {} fun f2(function: () -> Unit) {} } Now, if I use this with extension function, fun Context.temp(function: Test.() -> Unit) { function.onSuccess() // doesn't work } Calling this from Activity: temp {