Android Studio 3.1稳定版Theme与?attr/actionBarSize属性报错求助
Hey there, let’s tackle these two issues you’re facing in Android Studio 3.1 stable version one by one:
Issue 1: Error when selecting Android system Theme in styles.xml
Here are some troubleshooting steps to fix this:
- First, check your module-level
build.gradlefile. Make sure the version of your AppCompat/Support Library matches yourcompileSdkVersion. For example, ifcompileSdkVersionis set to 27, your appcompat dependency should be something likecom.android.support:appcompat-v7:27.1.1—mismatched versions often cause theme-related errors. - Try syncing your project with Gradle files: Go to
File > Sync Project with Gradle Files. Sometimes cached Gradle data messes up theme recognition. - Clean and rebuild your project: Run
Build > Clean Projectfirst, thenBuild > Rebuild Project. This clears old build caches that might be causing resource conflicts. - Verify your styles.xml root theme: If you’re using the AppCompat library, ensure your theme inherits from an AppCompat base (like
Theme.AppCompat.Light.DarkActionBar) instead of a native Android theme (e.g.,android:Theme.Holo.Light). Native themes can clash with AppCompat components.
Issue 2: Error using
?attr/actionBarSize in layout files Try these fixes for the actionBarSize attribute error:
- Confirm your Activity class extends
AppCompatActivity(not the nativeActivity). The?attr/actionBarSizeattribute is part of the AppCompat library, so it won’t work with plain native Activities. - Check your app’s theme in styles.xml: Make sure your theme inherits from an AppCompat variant (e.g.,
Theme.AppCompat.Light). If you’re using a native Android theme, this attribute won’t be recognized. - Sync and rebuild your project again—same as the first issue, cached build files can prevent the attribute from being resolved correctly.
- If you don’t want to use AppCompat, you can switch to the native version:
android.R.attr.actionBarSize(note theandroidnamespace prefix). This works with native Android themes, but limits you to older theme systems.
内容的提问来源于stack exchange,提问作者Harsh Jain
相关产品推荐
相关产品推荐

