Tag: 安卓

Kotlin,如何获得searchView提交

我有searchView 我想在按下提交按钮时添加自定义操作。 但是我所能得到的就是 searchBar.setOnSearchClickListener { //do some stuff } 我发现的所有信息都是旧的,而不是来自kotlin lang。 当键盘上的搜索图标被录音时,我怎样才能触发一个动作?

Android上的Kotlin – 是否有最低的API级别要求?

我正在认真考虑在一个绿色的Android项目上使用Kotlin,但是我担心的是敲门声,其中最重要的是API级别的最低要求。 在其他平台上,新语言需要特定的操作系统版本(例如需要iOS 7的Swift),我想知道这里是否有类似的需求? 我一直在搜索各种Kotlin / Android的常见问题和Stackoverflow,但一直没能find这个信息。

代码A和代码B在Kotlin有什么不同?

我是Kotlin的初学者,能告诉我Kotlin的Code A和Code B有什么不同吗? 谢谢! 代码A class Person(val firstName: String, val lastName: String, var age: Int){ } 代码B class Person(firstName: String, lastName: String, age: Int){ }

当处于调试器模式时,Android Studio 1.5与Kotlin Pluginexception。 如何解决它?

10:57:54 AM Plugin Error: Kotlin threw an uncaught UnsupportedOperationException. Disable Plugin 10:57:54 AM UnsupportedOperationException: null 看到Kotlin插件得到exception的时候遇到了Android studio显示的java stackframe。 更新:我很久以前更新了kotlin,但Exception仍然存在。 (不知道降价的原因) 我想也许在gradle构建文件的ext version仍然使用beta版本,我会尝试更改gradle中的版本 解决了 其实它是与gradle build file关联的,IDE错误只会让我更新IDE的插件,而不是kotlin扩展本身。 更改buildscript ext.kotlin_version = ‘1.0.0-beta-4589’ ,问题就消失了

在使用Kotlin协同程序时,与Room dao类错误

我试图使用kotlin协同程序通过这里描述的方法访问房间数据库,添加了插件和依赖项,并启用了gradle中的kotlin协程。 在gradle文件中: kotlin { experimental { coroutines ‘enable’ } } dependencies { implementation “org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21” …} 所以我为dao类中的所有方法添加了suspend关键字,如下所示: 道class @Query(“select * from myevent”) suspend fun all(): List @Delete suspend fun deleteEvent(event: MyEvent) … 并建立,然后得到这些错误 错误 e: C:\Users\projectpath\app\build\tmp\kapt3\stubs\debug\com\robyn\myapp\data\source\local\EventsDao.java:39: error: Deletion methods must either return void or return int (the number of deleted rows). public abstract java.lang.Object deleteEventById(@org.jetbrains.annotations.NotNull() ^ […]

为什么使用Kotlin“by”通过匿名子类?

我目前正在观看来自Google I / O 2017的video ,并遇到了Kotlin by特性。 下面的例子是为了避免在实际上只关心其中一个接口的时候实现接口的每一种方法。 by实施(从video): class MyListener : TransitionListener by EmptyTransitionListener { override fun onTransitionStart(transition: Transition) { } } object EmptyTransitionListener : TransitionListener { override fun onTransitionEnd(transition: Transition) {} override fun onTransitionResume(transition: Transition) {} override fun onTransitionPause(transition: Transition) {} override fun onTransitionCancel(transition: Transition) {} override fun onTransitionStart(transition: Transition) {} } window.sharedElementEnterTransition.addListener(MyListener()) […]

Rx和Kotlintypes推断中的generics函数引用失败

我在Kotlin写了一个方法: fun fetchDepositSession(): Completable = Observable.fromIterable(session.accounts) .map(DepositSession::DepositAccount) .toList() .doOnSuccess(depositSession::depositAccounts::set) .flatMapObservable(Observable::fromIterable) .map(DepositSession.DepositAccount::account::get) .toCompletable() 该行.flatMapObservable(Observable::fromIterable)正在导致一个错误:

如何在Kotlin中使用get()定义类的types属性

如何在Kotlin中使用get()来定义一个属性,它返回一个类,我在下面尝试,但不是编译 val targetActivity: Class get() = MyActivity.class

如何在Kotlin中编写扩展函数?

我只是想将我的正常function转换为Kotlin的扩展function。 这是我的function, fun hideKeyboard(activity: Activity) { if (activity != null) { activity.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_SATE_HIDDEN) val view: View = activity.currentFocus if (true) run { val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.hideSoftInputFromWindow(view.windowToken, 0) } } }

如何实现一个视图的Kotlin函数

我需要知道如何将函数实现到Kotlin中的ConstraintLayout。 我需要这样的东西: fun applyCustomPropeties(){ //some stuff } val rootLayout = findViewById(R.id.rootLayout) rootLayout.applyCustomPropeties() 谢谢。