Tag: anko

Android Studio在构建Kotlin项目时报告“无法识别启动活动:找不到默认活动”

我正在尝试使用Kotlin和Anko构建一个Android应用程序。 当我在Android Studio中选择“运行”时,出现错误: 无法识别启动活动:找不到默认活动 启动活动时出错 和应用程序不启动。 模拟器和真正的手机都出现这个错误。 为了尝试缩小这个问题,我尝试了几个示例Anko项目,其中包括android-anko-sample ,他们都展示了同样的破坏行为。 我有其他Android项目,我用Java编写,他们运行没有这个问题,这表明这是一个Kotlin或Anko特定的问题。 我甚至可以在我的一个Java应用程序和上面链接的“android-anko-sample”应用程序之间来回切换,并且始终如一地重现android-anko-sample的问题,而我的Java应用程序每次都能正常工作。 我已经看过涉及这个错误信息的其他问题,并且发布的解决方案要么不适用,要么没有帮助。 有一件事我注意到,奇怪的是,当我在Android Studio中打开AndroidManifest.xml (这些Anko应用程序中的任何一个)时,活动的名称显示为红色,就好像它们是错误一样。 以下是来自android-anko-sample的内容: 请注意,该应用程序确实安装在手机/模拟器上,我可以点击图标并运行它。 当我从Android Studio中选择运行时,它不会自动启动,这很不方便。 我该如何解决这个问题? 我在用着: Android Studio 2.1.2 Ubuntu Linux 16.04 Oracle JDK 1.8.0_131-b11 代码在这里: https://github.com/vsouhrada/android-anko-sample 几个Android Studio窗格的完整内容可以在这个要点中获得: https://gist.github.com/xenomachina/e8027b385661038c3f020a543493eebf

在Anko DSL中创建一个自定义View / ViewGroup类

我想创建一个自定义的视图,这只是一些Android视图的包装。 我研究了创建一个自定义的ViewGroup来管理它的子视图的布局,但我不需要这样的复杂性。 我基本上想要做的是这样的: class MainActivity verticalLayout { textView { text = "Something that comes above the swipe" } swipeLayout { } } class SwipeLayout linearLayout { textView { text = "Some text" } textView { text = "Another text" } } 原因是我想将SwipeLayout代码移到一个单独的文件中,但不想自己做任何复杂的布局。 这可能使用Anko吗? 编辑︰建议, 是否有可能重用Kotlin中的布局Anko解决了这个问题,如果视图是根布局。 但是,如示例中所示,我想在另一个布局中包含此内容。 那可能吗?

安科0.8 – 未解决的lparams参考

主要的问题是: lparams 以下片段无法编译: verticalLayout { }.lparams(width = matchParent, height = matchParent) { topMargin = dip(10) } 虽然这工作没有任何问题: verticalLayout { layoutParams = LinearLayout.LayoutParams(matchParent, matchParent).apply { topMargin = dip(10) } } 我不介意太多的第二个选项,但是你必须在生成参数的时候指定布局类型,这样会比较麻烦(也比原来的解决方案更脆弱)。 我还没有在Anko GitHub页面上找到任何东西,更新日志,或者通过浏览最近的提交。 以下是完整的UI类供参考: class ReviewsFragmentUi(ctx: AnkoContext<ReviewsFragment>) : AnkoComponent<ReviewsFragment> { override fun createView(ui: AnkoContext<ReviewsFragment>) = ui.apply { verticalLayout { layoutParams = LinearLayout.LayoutParams(matchParent, matchParent).apply { topMargin = […]

Android微调不响应点击,不关闭和OnItemSelectedListener不会触发

我正在Kotlin开发一个应用程序(如果你不知道kotlin,我相信你仍然可以帮助你的Android / Java经验) 细节: 我有一个微调在那里我的应用程序。虽然它没有响应点击一旦弹出,甚至显示一些奇怪的意见。 因为OnItemSelected侦听器永远不会被触发。 我开始从AsyncRealm调用更新微调器的方法。 代码如下: 整个函数运行时,微调框不为空,在附加侦听器之后,它也不再为空(调试时)。 private fun updateCategorySpinner(result: MutableList<Category>) { info("updateCategorySpinner") val arrayAdapter: ArrayAdapter<String> = ArrayAdapter(ctx, R.layout.spinner_item, result.map{ it.category }) arrayAdapter.setDropDownViewResource(R.layout.spinner_item) arrayAdapter.notifyDataSetChanged() categorySpinner.adapter = arrayAdapter info("updateCategorySpinner done") } result.map {..}创建一个带类别名称的MutableList。 问题: 我不知道为什么有这些箭头,但不管我使用什么布局(即使只是一个简单的TextView),他们在那里 我在这里错过了什么? 禁用监听器不会有帮助。 用Anko来接听听众并没有帮助。 侦听器在初始化时触发一次,就是这样。 一旦下拉菜单打开,它就完全卡住了。 我正在与Anko创建我的观点。 R.layout.spinner-item只是一个<Textview> 。 class AddTodoFragmentUi:AnkoComponent<ViewGroup>,AnkoLogger { override fun createView(ui: AnkoContext<ViewGroup>): View { val editTextTheme […]

anko记录器库在调试版本或签名版本中记录消息

我正在尝试使用anko公共库在logcat上记录调试消息。 我想在调试版本中显示日志消息而不是在签名版本。 我知道我可以使用Proguard删除签名版本中的日志记录。 我想知道如果anko库本身只有在调试版本的情况下记录消息? 或者它在签名的版本呢? 这是anko库的Logger工具https://github.com/Kotlin/anko/blob/d5a526512b48c5cd2e3b8f6ff14b153c2337aa22/anko/library/static/commons/src/Logging.kt /** * Send a log message with the [Log.DEBUG] severity. * Note that the log message will not be written if the current log level is above [Log.DEBUG]. * The default log level is [Log.INFO]. * * @param message the function that returns message text to log. * `null` […]

测试AnkoComponents和嘲笑AnkoContext

我在Kotlin编写一个Android应用程序。 我也使用Anko视图库来用程序化视图创建来替换xml。 我想写我的观点(这是AnkoComponents)的规格。 有没有一个公认的方法来做到这一点? 我似乎无法通过Google搜索或查看Anko文档来查找规格+ anko的任何信息。 具体来说,我想测试createView(ui : AnkoContext<T>)方法。 更具体地说(我希望能回答这个问题),我该如何模拟一个AnkoContext<T> ,我可以在我的测试中通过AnkoContext<T> ?

使用Anko SQLLite,检查数据库是否存在的最好方法是什么?

我正在使用Kotlin开发一个Android应用程序,并且作为启动过程的一部分,我想确定SQL Lite数据库是否已经存在(意味着用户不是新用户) 到目前为止,我还无法确定使用Anko SQLLite助手的ManagedSQLiteOpenHelper帮助程序基础结构执行此操作的最佳方法。 database.use { // what should go in here??? } 我不一定要查询一个不存在的表,因此抛出一个异常,并将其用作逻辑控制的一种形式,有没有更好的方法?

无法得到类型为…的对象的未知属性“anko_version”?

我想用我的Android Kotlin项目来使用Anko。 我已经添加行到我的依赖/ gradle模块文件,如下所示: dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" compile "org.jetbrains.anko:anko:$anko_version" compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support:design:26.+' compile 'com.android.support:support-vector-drawable:26.+' compile 'com.android.support:support-v4:26.+' testCompile 'junit:junit:4.12' compile 'com.android.support.constraint:constraint-layout:1.0.2' } 但是在尝试执行gradle同步时遇到以下错误: 错误:(36,0)无法获取类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象的未知属性“anko_version”。 打开文件 我如何正确地将Anko纳入我的项目? 作为参考,我正在使用Android Studio 2.0。

带有ArrayAdapter的Anko DSL

今天,我一直在努力将我的一个应用程序转换为纯粹的kotlin构建。 我正在努力与阵列适配器目前,并得到这个错误。 File from xml type layout resource ID #0x7f0c000a 这是我的活动有错误。 class KotlinTest : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val arr = Array(5, Int::toString) verticalLayout { id = R.id.test_text_layout textView { width = matchParent height = matchParent id = R.id.test_text_item } listView { id = R.id.test_text_view } } val cardAdapter: ArrayAdapter<String>? = […]

从Fragment调用Anko toast()方法会导致java.lang.NoSuchMethodError

当我从Android Fragment调用toast(“Toast的消息文本”)时出现以下错误: java.lang.NoSuchMethodError:无虚方法getActivity()Landroid / app / Activity; 在类Landroid / support / v4 / app / Fragment中; 或者它的超类(“android.support.v4.app.Fragment”声明出现在文件类名索引中) 我使用的是Anko v0.9.1和Kotlin 1.0.6 什么可能是这次崩溃的原因? 标准的Android吐司工作得很好。 另外Toast()函数在Activity内工作。