我有这个问题:
错误:
C:\Users\avi12\OneDrive\Documents\AndroidApps\WhatsApp Easy Sticker Maker\app\src\main\java\com\avi12\whatsappeasystickermaker\MainActivity.kt: (20, 13): Overload resolution ambiguity:
public inline fun ViewManager.textView(init: (@AnkoViewDslMarker TextView).() -> Unit): TextView defined in org.jetbrains.anko
public inline fun ViewManager.textView(init: (@AnkoViewDslMarker TextView).() -> Unit): TextView defined in org.jetbrains.anko
我刚刚发现Anko的代码:
package com.avi12.whatsappeasystickermaker
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import org.jetbrains.anko.design.*
import org.jetbrains.anko.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
coordinatorLayout {
textView {
text = "Begin by tapping the + button"
}
floatingActionButton {
}
}
}
}
Anko版本:0.10.8
Android Studio版本:3.3
答案 0 :(得分:1)
似乎是问题所在,是我在build.gradle
中遇到了
dependencies {
...
implementation "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
}
由于某种原因,这部分解决了该问题(成功构建后仍未预览):
dependencies {
...
// implementation "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
}
答案 1 :(得分:0)
...仅当我们在实现AnkoComponent接口的外部类中定义布局时,才可以使用。下面是我们如何修改活动以在单独的类中定义视图的方法:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MainActivityUI().setContentView(this)
}
class MainActivityUI : AnkoComponent<MainActivity> {
override fun createView(ui: AnkoContext<MainActivity>) = with(ui) {
verticalLayout {
gravity = Gravity.CENTER
padding = dip(20)
textView {
gravity = Gravity.CENTER
text = "Enter your request"
textColor = Color.BLACK
textSize = 24f
}.lparams(width = matchParent) {
margin = dip(20)
}
val name = editText {
hint = "What is your name?"
}
editText {
hint = "What is your message?"
lines = 3
}
button("Enter") {
onClick {
toast( "Hey ${name.text}! Thank you for contacting us. We will get in touch with you soon.")
}
}.lparams(dip(280), sp(80))
}
}
}
}
我希望它能解决问题,我很快就会发现...