Tag: anko

如何在values / ids.xml中获得自定义ID的引用

我在回收视图适配器中使用anko来创建视图的视图。 我已经做到了这一点,但不知道如何使用kotlin综合视图id(我想得到它没有findViewById) 值/ ids.xml 我的Anko getView代码: private fun getView(context: Context): View{ return with(context){ linearLayout { lparams(width = matchParent, height = wrapContent) padding = dip(10) orientation = android.widget.LinearLayout.HORIZONTAL //Task Number textView { id = R.id.txv1 text = “TextView 22” textSize = 16f typeface = Typeface.MONOSPACE padding =dip(5) }.lparams(){ weight = 1f } //Task Name textView { […]

当使用kotlin找不到文件时,如何从URL.readText()中获取错误

当我的手机上没有互联网,或者当这个URL不存在时,这个方法没有做任何事情,既不会崩溃也不会停止搜索。 我试过这个: doAsync{ val json:String json = try { URL(“http://10.0.2.2:8888/bac/orient.php?ort=1”).readText() }catch (e: IOException){ e.printStackTrace() “” } uiThread{toast(json)} }

有没有干净的干净的方式来从HTTP请求JSON更新多个textViews?

我有以下Kotlin / Anko / Android活动。 import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.widget.TextView import com.fasterxml.jackson.module.kotlin.readValue import com.github.kittinunf.fuel.Fuel import eu.gwapi.laaketilaus.util.JSON import eu.gwapi.laaketilaus.util.Order import org.jetbrains.anko.find import org.jetbrains.anko.textView import org.jetbrains.anko.toast import org.jetbrains.anko.verticalLayout class OrderDetailsActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val order_id: Long = intent.extras.getLong(“order_id”) verticalLayout { textView { id = R.id.order_detail_customer } textView { id = […]

如何设置android应用程序的自定义字体?

我似乎无法将标准的android字体更改为我的应用程序中的另一个。 我正在Kotlin写我的应用程序,我正在使用Anko进行布局。 我试过了: typeface = Typeface.create() typeface = Typface.createFromAsset(assets, “font/font_name”) setTypeface(Typeface.createFromAsset(assets, “font/font_name”)) 谢谢您的帮助。

使用Anko访问活动的视图

我知道我可以使用Anko的id属性来识别视图: class MainActivityUI : AnkoComponent { override fun createView(ui: AnkoContext) = with(ui) { frameLayout { textView { id = R.id.text } } } } 然后使用find()函数(或使用Kotlin Android扩展)在Activity获取它: class MainActivity : AppCompatActivity() { private val textView by lazy { find(R.id.text) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MainActivityUI().setContentView(this) textView.text = “Hello World” } } 但我觉得我失去了一些东西; README中唯一提到find函数或Kotlin Android扩展的地方在标题为支持现有代码的部分: […]

如何使用Anko设置FloatingActionButton边框宽度

我刚刚从Java切换到Kotlin,并使用Anko来构建布局 。 这是我的布局: relativeLayout { floatingActionButton { imageSource = R.drawable.kotlin_is_amazing }.lparams { width = wrapContent height = wrapContent } } 现在的问题是如何设置app:borderWidth与Anko app:borderWidth ?

Kotlin:如何使用Anko DSL制作工具栏菜单?

如何直接在UI类中使用Anko DSL制作Android工具栏菜单? 不想在我的Activity类中写入监听器。 关于我下面给出的答案,有没有办法避免XML recource文件来描述菜单项?

Android Anko警报与自定义视图错误(Kotlin)

我想创建一个使用anko自定义元素的警告对话框。 我find的每个指南和教程都使用这种方法: alert { customView { textView(“Hello”) } }.show() 但是我在customView出现错误: Error:(73, 13) Type inference failed: Not enough information to infer parameter T in inline fun Activity.customView(theme: Int = …, init: T.() -> Unit): T Please specify it explicitly. Anko有什么变化,而且没有记录?

Android Studio 3.0 Canary 1:Gradle同步错误

我在我的Kotlin项目中遇到这个错误: 这是我的应用程序的Gradle文件: 除了添加Kotlin和Anko的依赖外,我还没有真正做过这个项目。 不知道发生了什么…

是否有可能重新使用Kotlin Anko的布局

我读到使用Anko的最大好处是它的可重用性。 但我无法find确切的例子。 目前在新的Android布局系统中,锅炉板如下: DrawerLayout (with some setup) CoordinatorLayout (with some setup) AppBarLayout (with some setup) ToolBar NavigationView (with header inflated) 从上面的布局结构来看,只有是varry。 在很多情况下,这些仪式设置几乎在每个活动中都重复着。 所以在这里与安科即时思考如果有一个可重用的解决方案关于这个问题。 我不期望它可以重复使用的通用布局,但至少我可以尽量减少项目中的仪式代码。 也许我需要像这样的东西: class MainUI: AnkoComponent { override fun createView(ui: AnkoContext): View{ return with(ui) { myCustomRootLayout { //here is what will be } } } } 从上面的代码,我期待myCustomRootLayout将做所有的根布局,如(DrawerLayout,CoordinatorLayout等)的仪式设置。 那可能吗? 编辑所以我想我的问题是: 如何使一个自定义组件可以承载其他组件