问题:
I'm using Navigation Architecture Components, and I wanted to take advantage of the safe args plugin.
I want to add some arguments to one of my fragments in the navigati...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I'm using Navigation Architecture Components, and I wanted to take advantage of the safe args plugin.
I want to add some arguments to one of my fragments in the navigation graph. The arguments code is generated via the Design editor. Here's a snippet:
<fragment
android:id="@+id/inAppPurchaseFragment"
android:name="purchaseFragment" >
<argument
android:name="attribution_id"
app:type="string" />
</fragment>
However, I'm getting an error in Android Studio (3.2 Canary 16) that says it cannot resolve the symbol 'string', or any type I try to use. Have any of you had this issue & do you know why it's occurring?
Update for more context; I get this error during build on the line that has app:type="string"
:
error: 'string' is incompatible with attribute type (attr) integer.
回答1:
Your code looks good, make sure you add a defaultValue to it
android:defaultValue="something"
And by the way, have you implemented Navigation Architecture Components
as it says on adding-components documentation
?
dependencies {
def nav_version = "1.0.0-alpha02"
implementation "android.arch.navigation:navigation-fragment:$nav_version" // use -ktx for Kotlin
implementation "android.arch.navigation:navigation-ui:$nav_version" // use -ktx for Kotlin
// optional - Test helpers
androidTestImplementation "android.arch.navigation:navigation-testing:$nav_version" // use -ktx for Kotlin
}
回答2:
Make sure to put
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha02"
in your project level build.gradle
and put
apply plugin: 'androidx.navigation.safeargs'
in your application level build.gradle.
.................
android:defaultValue
is optional