Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rendering issue with android API 22

When creating a new project in Android Studio while using the latest updates and after adding compile com.android.support:appcompat-v7:22.1.0 to the dependencies still have this issue (which is solved if I'm using API 21):

Exception Details java.lang.NoSuchFieldError: View_theme   at android.support.v7.internal.widget.ViewUtils.themifyContext(ViewUtils.java:124)   at android.support.v7.widget.Toolbar.(Toolbar.java:198)   at android.support.v7.widget.Toolbar.(Toolbar.java:192)   at java.lang.reflect.Constructor.newInstance(Constructor.java:422)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)   at com.android.layoutlib.bridge.bars.BridgeActionBar.(BridgeActionBar.java:84)   at com.android.layoutlib.bridge.bars.AppCompatActionBar.(AppCompatActionBar.java:56)

When i opened projects that was originally created with eclipse the rendering for API 22 worked great on Android Studio .

Can someone please explain this ?

Another issue that i encountered is that when upgrading the SDK it adds the Android M API and it called API 22 just as Android 5.1.1 which can also cause rendering issues . The solution is just to switch back to API 22 5.1.1 Hope it helps .

like image 843
liorlis Avatar asked Nov 01 '22 05:11

liorlis


2 Answers

Update : Doing a Build>Clean Project or a gradle Sync Project will solve the problem.

Old answer : According to 22.1 changelog (source) :

Lollipop added the ability to overwrite the theme at a view by view level by using the android:theme XML attribute - incredibly useful for things such as dark action bars on light activities. Now, AppCompat allows you to use android:theme for Toolbars (deprecating the app:theme used previously) and, even better, brings android:theme support to all views on API 11+ devices.

So i guess if you change app:theme to android:theme it will work.

like image 97
Hugo Gresse Avatar answered Nov 15 '22 07:11

Hugo Gresse


In my case, solution was as simple as

  1. Add @style to the parent theme
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
  1. remove android.support.v7.widget. from Toolbar

  2. move from app:theme to android:theme

<Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
like image 23
Eloi Navarro Avatar answered Nov 15 '22 07:11

Eloi Navarro