[英]What is app:overlayImage in xmlns:app="http://schemas.android.com/apk/res-auto?
[英]Kotlin- xmlns:app=“http://schemas.android.com/apk/res-auto” is unavailable
我正在關注kotlin 基礎代碼實驗室,其中說 API 21 下的任何內容都會將矢量圖像轉換為 png 圖像並防止我需要添加xmlns:app="http://schemas.android.com/apk/res-auto"
到activity_main.xml
文件並按下Sync Now
,然后將vectorDrawables.useSupportLibrary = true
添加到.gradle(:app
) 文件中的defaultConfig { }
中。 我跟着一切,但我一直得到一個錯誤:
/Users/Home/IdeaProjects/DiceRoller/app/src/main/res/layout/activity_main.xml:12
錯誤:屬性 android:srcCompat 未找到。
錯誤:鏈接文件資源失敗。
我意識到xmlns:app="http://schemas.android.com/apk/res-auto"
行是灰色的
這是我正在使用的 gradle 版本:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18
是什么導致了這個問題?
activity_main.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
tools:context=".MainActivity">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/diceImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:srcCompat="@drawable/empty_dice"
tools:src="@drawable/dice_1">
</android.support.v7.widget.AppCompatImageView>
構建:等級(:應用程序)
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.diceroller"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
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:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-beta02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
build.gradle:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is because the srcCompat
attribute only exists in the app
( http://schemas.android.com/apk/res-auto
) namespace for the AppCompatImageView
class (see the API documentation for more info), not the default android
( http://schemas.android.com/apk/res/android
)命名空間。
要解決此問題,只需將android:srcCompat
的android
部分重命名為app:srcCompat
:
<android.support.v7.widget.AppCompatImageView
app:srcCompat="@drawable/empty_dice" />
(PS 考慮自動關閉 XML 標簽,這樣您就不必編寫更多代碼來關閉 XML 元素。有關更多信息,請參閱此問題)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.