I'm learning material design using the Theme.Material.Light.NoActionBar theme. I'm trying to add a toolbar to my Activity following the tutorial here.
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
v21\style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
</resources>
tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/colorPrimary"
android:elevation="4dp">
</android.support.v7.widget.Toolbar>
build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
testCompile 'junit:junit:4.12'
}
But I'm getting this Rendering Problem
Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style 'toolbarStyle' in current theme
Everything I've tried so far didn't work
- Refreshing the layout.
- Updated android studio to the latest version
2.2.2and installed everything was recommended for me in the top-right pop-ups. - Clicking on
File>Invalidate caches/restart. - Changing the
API version in editorin the preview window to21,22,23,24and25-I can't try preview on versions less then 21(a material design requirement/ or am I wrong???)-. - Changed the
Theme in editorin the preview window to aNoActionBarmaterial theme and to theAppTheme-There's no use of changing it toAppCompattheme since I won't be able to view material elements like cards and so on-. - I did also try to change it to
AppCompat, but when I choose it from the themes list and press ok, it doesn't become the selected one;AppThemebecomes the selected theme for preview instead.
I tried also to add <item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item> but it gave me another warning : Failed to find '?attr/actionBarSize' in current theme.
What could the problem in the preview be, and how can I fix it.
Another question, as I understand until now, AppCompat theme doesn't contain all features of Material themes. Why would other people use it to solve the problem of preview or even add a reference to it in the v21\style.xml file instead of referencing to a Toolbar that exists in the Material themes?
