示例布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<include layout="@layout/toolbar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:padding="@dimen/spacing_xlarge"
>
</LinearLayout>
</FrameLayout>
使用下面的gradle构建文件,Android Studio(3.1.3)将?attr/actionBarSize
标记为红色,并声明为红色
无法解析符号
?attr/actionBarSize
使缓存无效并重新启动android studio无效
都没有添加
implementation "com.android.support:support-v4:$support_version"
到模块gradle构建文件。
如何让android studio识别设置?
如
所示,我可以向其中添加android:
名称空间
但据我了解,它会查找其他属性。
build.gradle(项目)
buildscript {
ext.kotlin_version = '1.2.50'
ext.anko_version = '0.10.5'
ext.support_version = '27.1.1'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
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 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "foo.bar.App"
minSdkVersion 19
targetSdkVersion 27
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:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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-jdk7:$kotlin_version"
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
implementation "com.google.code.gson:gson:2.8.1"
implementation "com.squareup.picasso:picasso:2.5.2"
}
答案 0 :(得分:4)
尝试?android:attr/actionBarSize