我創建了一個簡單的 Android Studio 啟動專案(基本活動),在添加一個簡單的樣式檔案后出現鏈接錯誤res/values/app_styles.xml:
<resources>
<style name="MyFab" parent="Widget.MaterialComponents.ExtendedFloatingActionButton">
<item name="iconTint">?attr/colorOnBackground</item>
<item name="app:fabSize">mini</item>
<item name="app:tint">?attr/colorOnPrimary</item>
</style>
</resources>
app命名空間似乎是未知的,Android Studio每個app:**專案都以紅色突出顯示,并且構建失敗并出現鏈接錯誤:
Android resource linking failed
xxx.myapp.app-mergeDebugResources-43:/values-w600dp-v13/values-w600dp-v13.xml:6: error: style attribute 'app:attr/fabSize' not found.
xxx.myapp.app-mergeDebugResources-43:/values-w600dp-v13/values-w600dp-v13.xml:7: error: style attribute 'app:attr/tint' not found.
error: failed linking references.
我在這里做錯了什么?我應該使用不同的檔案名/位置嗎?
PS:Android Studio 海豚 | Mac x64 上的 2021.3.1 補丁 1,全新安裝。
專案依賴:
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
uj5u.com熱心網友回復:
您必須洗掉定義app中屬性名稱中的前綴。style
請注意,這ExtendedFloatingActionButton是一個子類MaterialButton,而不是FloatingActionButton。這意味著適用于FloatingActionButton具有不同命名的幾個屬性ExtendedFloatingActionButton或不存在。
fabSize并且tint不存在于ExtendedFloatingActionButton.
<style name="MyFab" parent="Widget.MaterialComponents.FloatingActionButton">
<item name="iconTint">?attr/colorOnBackground</item>
<item name="fabSize">mini</item>
<item name="tint">?attr/colorOnPrimary</item>
</style>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/520729.html
