gpt4 book ai didi

navigation-drawer - 可以使用提供的参数调用以下函数。向上导航

转载 作者:行者123 更新时间:2023-12-02 16:54:22 31 4
gpt4 key购买 nike

我正在使用 android 导航组件开发 android,但我收到以下警告 None of the following functions can be called with the arguments provided.navigateUp(NavController, DrawerLayout?) 定义在androidx.navigation.ui.NavigationUInavigateUp(NavController, AppBarConfiguration) 定义在androidx.navigation.ui.Navigation

below my MainActivity.kt

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI


import androidx.navigation.ui.setupWithNavController
import com.example.forecastmvvm.R
import kotlinx.android.synthetic.main.activity_main.*



class MainActivity : AppCompatActivity() {
private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
navController = Navigation.findNavController(this,R.id.nav_host_fragment)
bottom_nav.setupWithNavController(navController)
NavigationUI.setupActionBarWithNavController(this, navController)
}

override fun onSupportNavigateUp(): Boolean {
return NavigationUI.navigateUp( null, navController)
}


}

在 app.gradle 下

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: "kotlin-kapt"

apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.forecastmvvm"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.0.0"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation "android.arch.navigation:navigation-fragment:1.0.0"
implementation "android.arch.navigation:navigation-ui:1.0.0"
implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0"
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0"

implementation "androidx.core:core-ktx:1.0.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"

// Room
implementation "androidx.room:room-runtime:2.1.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
kapt "androidx.room:room-compiler:2.1.0"

// Gson
implementation "com.google.code.gson:gson:2.8.5"

// Kotlin Android Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"

// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.0.0"
implementation "com.squareup.retrofit2:converter-gson:2.0.0"
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

// ViewModel
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0"
kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"

// Kodein
implementation "org.kodein.di:kodein-di-generic-jvm:6.3.3"
implementation "org.kodein.di:kodein-di-framework-android-x:6.3.3"

// Better dateTime-time support even on older Android versions
implementation "com.jakewharton.threetenabp:threetenabp:1.1.0"

// Glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'

// Groupie RecyclerView
implementation 'com.xwray:groupie:2.1.0'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.1.0'

// Preference
implementation "androidx.preference:preference:1.0.0"

// WeatherLocation
implementation "com.google.android.gms:play-services-location:16.0.0"

// New Material Design
implementation "com.google.android.material:material:1.0.0"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}

在渐变之下

buildscript {
ext.kotlin_version = '1.3.41'
ext.room_version = '2.1.0'
ext.navigation_version = '1.0.0'
ext.kodein_version = '6.3.3'
ext.lifecycle_version = '2.0.0'
ext.retrofit_version = '2.0.0'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

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

最佳答案

据我所知,第一个参数应该是你的NavigationController(不可为空),你的第二个参数是DrawerLayout(可空)

你应该翻转你的参数

override fun onSupportNavigateUp(): Boolean {
return NavigationUI.navigateUp( navController, null )
}

Parameter Arguments Screenshot

关于navigation-drawer - 可以使用提供的参数调用以下函数。向上导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57073111/

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