操作栏抽屉切换抓住用API 23(appcompat_v7)工作 [英] Action bar drawer toggle seizes to work with API 23 (appcompat_v7)

查看:349
本文介绍了操作栏抽屉切换抓住用API 23(appcompat_v7)工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近包括应用程序兼容性V7库到我的项目。在试图摆脱一堆错误的,我更新了我大部分的SDK文件,并从21的问题是,我的老code设计的抽屉式导航切换(汉堡包符号/箭头改变了我的目标SDK版本23号)现在不工作,并通过投食,并显示在文件中的错误。

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.

这里的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的错误读取:没有资源的发现,给定的名称匹配:ATTRbarSize

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)

...

这同样code,当我与API 21.如何使用API​​ 23风格抽屉切换箭任何想法编纂工作?

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

推荐答案

您可以在23 API使用Android设计支持库和修改导航栏。它很容易使用和花费较少的时间,以使如此,因为它只是一个XML标记。而这个库是向后兼容的。

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.

添加到您的gradle:

Add this to your gradle:

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

值得修改code。由于Android的设计支持会减少很多笨拙的前设计导航栏需要。 code的一小peice的会给你一个导航栏。

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>

这篇关于操作栏抽屉切换抓住用API 23(appcompat_v7)工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆