1

example layout:

<?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>

With the gradle build files below, Android Studio (3.1.3) marks the ?attr/actionBarSize red, claiming it

cannot resolve symbol ?attr/actionBarSize

Invalidating the caches and restarting android studio has no effect,

neither has adding

implementation "com.android.support:support-v4:$support_version"

to the module gradle build file.

How do I get android studio to recognise the setting?

I could add the android: namespace to it, as suggested by

Cannot resolve symbol '?attr/actionBarSize' after updating Android Studio from 2.3 to 3.0 for buildToolsVersion '26.0.2'

but the way I understand it, that would look up a different property.

build.gradle(Project)

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 (Module)

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"
}
User1291
  • 7,664
  • 8
  • 51
  • 108
  • 2
    It's one of the bugs in Android Studio. It will be fixed soon. You can compile your app without any errors even if it's red. https://www.reddit.com/r/androiddev/comments/8s8q7m/what_is_up_recently_with_the_quality_of_android/ – Thracian Jun 21 '18 at 13:05
  • @Thracian Interesting link. It seems there are a lot of issues since 3.1. A lot of things are marked as red on my project when it actually works. Removing .idea and clear the cache help to solve some of them for a time, but they finally come back. Hope Google will fix all of that soon and increase the stability – Eselfar Jun 21 '18 at 16:51
  • @Eselfar same here. Getting lots 'IDE Error Occurred', imported modules not appearing and binding libraries are not imported and more. It will get fixed soon. AS getting better most of the releases. – Thracian Jun 22 '18 at 08:57

2 Answers2

4

try ?android:attr/actionBarSize

Pratik Mhatre
  • 779
  • 7
  • 12
1

change to

?android:attr/actionBarSize

or

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Lam Nguyen
  • 565
  • 1
  • 5
  • 7