I had the following rendering issue on all my layouts when using SDK 22 to preview them.
Error inflating class android.support.v7.widget.Toolbar.
java.lang.NoSuchFieldError: View_theme
In my case , the problem was styles.xml
:
XML with rendering problem:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
<!-- Base application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
</style>
</resources>
XML without problem:
<resources>
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar" />
<!-- Base application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
</style>
</resources>
Notice how I had to add @style/
in the parent reference. That seems to solve my problem (after a rebuild).
Question, is this an error on my side, or a bug? Many tutorials don't put it (Including Official Android Page)
Gradle:
compileSdkVersion 22
buildToolsVersion '22.0.1'
minSdkVersion 15
targetSdkVersion 22
classpath 'com.android.tools.build:gradle:1.1.0'
Final Note: I'm not using Toolbar.
EDIT :
Reading from another SO question.
If your activity extends AppCompactActivity
, your parent theme should be
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar" />
where as, if using ActionBarActivity
, theme should be
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
I think the difference is on purpose, and not a bug. Please feel free to correct me if i am wrong as i cannot conferm the same from anywhere yet.
OLD :
To use Toolbar as an action bar, the first thing you need to do is disable the decor provided action bar. The easiest way is to have your theme extend from Theme.AppCompat.NoActionBar (or the light variant).
Use :
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar" />
From this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With