gpt4 book ai didi

android - Anko floatingActionButton 的依赖项缺失或冲突

转载 作者:行者123 更新时间:2023-11-29 14:12:56 24 4
gpt4 key购买 nike

关注this slightly outdated tutorial之后,我一直在尝试使用 org.jetbrains.anko.design.floatingActionButton。错误是:

Cannot access class 'android.support.design.widget.FloatingActionButton'. Check your module classpath for missing or conflicting dependencies.

build.gradle(项目)

buildscript {
ext.kotlin_version = '1.1.50'
ext.anko_version = '0.10.1'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

build.gradle(应用程序)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "uk.co.danielstanton.todoapp.todoapp"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

compile "org.jetbrains.anko:anko:$anko_version"

// Anko + Android Support Libraries:

// Appcompat-v7 (Anko Commons and Layouts)
compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
compile "org.jetbrains.anko:anko-coroutines:$anko_version"

// CardView-v7
compile "org.jetbrains.anko:anko-cardview-v7:$anko_version"

// Design
compile "org.jetbrains.anko:anko-design:$anko_version"
compile "org.jetbrains.anko:anko-design-coroutines:$anko_version"

// GridLayout-v7
compile "org.jetbrains.anko:anko-gridlayout-v7:$anko_version"

// Percent
compile "org.jetbrains.anko:anko-percent:$anko_version"

// RecyclerView-v7
compile "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
compile "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"

// Support-v4 (Anko Commons and Layouts)
compile "org.jetbrains.anko:anko-support-v4:$anko_version"
}

主界面.kt

import android.support.v4.content.ContextCompat
import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import android.widget.ListView
import org.jetbrains.anko.*
import org.jetbrains.anko.appcompat.v7.toolbar
import org.jetbrains.anko.design.floatingActionButton
import org.jetbrains.anko.sdk25.coroutines.onItemLongClick

class MainUI(val todoAdapter: TodoAdapter) : AnkoComponent<MainActivity> {
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
return relativeLayout {
var todoList : ListView? =null

//textView displayed when there is no task
val hintListView = textView("What's your Todo List for today?") {
textSize = 20f
}.lparams {
centerInParent()
}

//function to show or hide above textView
fun showHideHintListView(listView: ListView) {
if (getTotalListItems(listView)>0) {
hintListView.visibility = View.GONE
} else {
hintListView.visibility = View.VISIBLE
}
}

//layout to display ListView
verticalLayout {
todoList=listView {
adapter = todoAdapter
onItemLongClick { adapterView, view, i, l ->
val options = listOf("Completed","In Progress","Not Started","Delete")
selector("Task Options", options) {dialogInterface, j ->
if (j == 3) {
var task=adapter.getItem(i)
todoAdapter?.delete(i)
showHideHintListView(this@listView)
longToast("Task ${task} has been deleted")
}else{
longToast("Task ${adapter.getItem(i).toString()} has been marked as \"${options[j]}\"")
}
}
true
}
}
}.lparams {
margin = dip(5)
}

//Add task FloatingActionButton at bottom right
floatingActionButton { // <-- HERE
imageResource = android.R.drawable.ic_input_add
onClick {
val adapter = todoList?.adapter as TodoAdapter
alert {
customView {
verticalLayout {
toolbar {
id = R.id.dialog_toolbar
lparams(width = matchParent, height = wrapContent)
backgroundColor = ContextCompat.getColor(ctx, R.color.colorAccent)
title = "What's your next milestone?"
setTitleTextColor(ContextCompat.getColor(ctx, android.R.color.white))
}
val task = editText {
hint = "To do task "
padding = dip(20)
}
positiveButton("Add") {
if(task.text.toString().isEmpty()) {
toast("Oops!! Your task says nothing!")
}
else {
adapter.add(task.text.toString())
showHideHintListView(todoList!!)
}
}
}
}
}.show()
}
}.lparams {
//setting button to bottom right of the screen
margin = dip(10)
alignParentBottom()
alignParentEnd()
alignParentRight()
gravity = Gravity.BOTTOM or Gravity.END
}
}.apply {
layoutParams = FrameLayout.LayoutParams(matchParent, matchParent)
.apply {
leftMargin = dip(5)
rightMargin = dip(5)
}
}

}

//function to get total number of items in list
fun getTotalListItems(list: ListView?) = list?.adapter?.count ?: 0
}

谢谢!

最佳答案

我遇到了同样的问题,要解决它,您只需要添加 Android 支持设计依赖项。因为,在您的情况下,您正尝试使用 Anko Layout 库添加 FAB,它依赖于上述引用的库。

只需将以下内容添加到您的应用程序依赖项中:

implementation 'com.android.support:design:26.1.0'

关于android - Anko floatingActionButton 的依赖项缺失或冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46464193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com