1

I recently included the appcompat v7 library to my project. In trying to get rid of bunch of errors, I updated most of my SDK files and changed my target SDK version to 23 from 21. The problem is, my old code for designing the Navigation Drawer Toggle (the hamburger sign/arrow sign) now doesn't work and throws and shows errors on the files through eclipse.

Here's the code:

 <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">false</item>
    <item name="barSize">16sp</item>
    <item name="gapBetweenBars">4sp</item>
    <item name="color">@android:color/white</item>
</style>

Here is its implementation in my custom theme:

<item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 

Eclipse error reads: No resource found that matches the given name: attr "barSize".

When I comment that out, the app runs but crashes with the error log:

09-20 01:09:39.852: E/AndroidRuntime(1662): FATAL EXCEPTION: main
09-20 01:09:39.852: E/AndroidRuntime(1662): Process: com.site.app, PID: 1662
09-20 01:09:39.852: E/AndroidRuntime(1662): java.lang.NoSuchMethodError: No static method getLayoutDirection(Landroid/graphics/drawable/Drawable;)I in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of 'android.support.v4.graphics.drawable.DrawableCompat' appears in /data/app/com.site.app-2/base.apk)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.support.v7.graphics.drawable.DrawerArrowDrawable.draw(DrawerArrowDrawable.java:337)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.widget.ImageView.onDraw(ImageView.java:1209)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.draw(View.java:15210)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.updateDisplayListIfDirty(View.java:14144)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.getDisplayList(View.java:14167)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.draw(View.java:14934)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.ViewGroup.drawChild(ViewGroup.java:3410)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3204)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.updateDisplayListIfDirty(View.java:14139)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.getDisplayList(View.java:14167)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.draw(View.java:14934)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.ViewGroup.drawChild(ViewGroup.java:3410)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3204)
09-20 01:09:39.852: E/AndroidRuntime(1662):     at android.view.View.draw(View.java:15213)

...

This same code worked when I was compiling with API 21. Any ideas on how to style the Drawer Toggle Arrow with API 23?

Visionwriter
  • 649
  • 6
  • 12
  • Did you upgrade support-v4 to the same version as AppCompat-v7 ? – BladeCoder Sep 25 '15 at 09:44
  • @BladeCoder I updated the Android Support Library through the SDK before importing the AppCompat-v7 library, although I still had to change the project.properties target from 20-23. Do I still need to update the v4 library individually and how do I go about doing that? – Visionwriter Sep 25 '15 at 10:06
  • If you included the support-v4 jar directly in your project you need to remove it. The version provided with the AppCompat-v7 library project should be OK. It would be easier if you used Android Studio though. – BladeCoder Sep 25 '15 at 12:03
  • The crash log suggests that some required methods are missing from support-v4 classes which would indicate that maybe you are using an obsolete version of support-v4 with a recent version of AppCompat-v7. DrawableCompat.getLayoutDirection() was added in support-v4 version 23. – BladeCoder Sep 25 '15 at 12:07
  • @BladeCoder Hmm...I actually also have android_support_v13 included in my project, which also contains a v4 library. So that may be it. I am thinking downloading the latest version of v13 may do the trick. – Visionwriter Sep 25 '15 at 12:16
  • Support-v13 includes utilities for native fragments. AppCompat-v7 uses support Fragments provided by support-v4. I think you should remove support-v13 completely if you use AppCompat. – BladeCoder Sep 25 '15 at 12:27
  • Great! @BladeCoder. It finally worked. The project was defaulting to the v4 library in the v13 library. Removing that solved the problem. Thanks! – Visionwriter Sep 25 '15 at 13:29
  • By the way, you should put a summary of this as an answer so I can choose it as the correct answer and others can benefit as well. @BladeCoder – Visionwriter Sep 25 '15 at 13:30

1 Answers1

0

You can use android design support libraries on API 23 and modify the Navigation bar. It is easy to use and takes less time to make that as it is just an XML tag. And this library is backward compatible.

Add this to your gradle:

compile 'com.android.support:design:22.2.1'

It is worth modifying the code. As Android design support will reduce a lot of clumsiness needed to design the navigation bar before. A small peice of code will give you a navigation bar.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

<!-- your content layout -->

<android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Vishal Sharma
  • 2,550
  • 1
  • 23
  • 40
  • How do I do that on eclipse? – Visionwriter Sep 20 '15 at 00:33
  • 1
    You can of course migrate your eclipse project to android studio and add these changes easily. If you don't want to use Android studio (not sure about the reason) then there are gradle plugins available for eclipse. https://marketplace.eclipse.org/content/gradle-integration-eclipse-0 But I'll still suggest to migrate to android studio – Vishal Sharma Sep 20 '15 at 00:37