更换pcated android.support.v4.app.ActionBarDrawerToggle与support.v7版本的原因抽屉里不是果冻豆的作品去$ P $ [英] Replace deprecated android.support.v4.app.ActionBarDrawerToggle with support.v7 version cause drawer not works on Jelly Bean

查看:231
本文介绍了更换pcated android.support.v4.app.ActionBarDrawerToggle与support.v7版本的原因抽屉里不是果冻豆的作品去$ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继<一个答案href="http://stackoverflow.com/questions/26439619/how-to-replace-de$p$pcated-android-support-v4-app-actionbardrawertoggle/26440823#26440823">this问题我已经取代 ActionBarDrawerToggle 支持V4库,在最新的更新(启21)一直pcated了最新的德$ P $ ActionBarDrawerToggle 支持-V7库

现在抽屉工程Andrid棒棒糖模拟器没有去precation警告,但是当我测试果冻豆真实设备上的应用程序没有抽屉,没有切换纸盒键显示。

什么appened此支持库更新的地狱?我怎么能解决这个问题,而不降级至previous版本?

下面我的布局

 &LT; android.support.v4.widget.DrawerLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent&GT;

    &LT;! - 内容视图 - &GT;

    &LT; RelativeLayout的
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:工具=htt​​p://schemas.android.com/tool​​s
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:paddingBottom会=@扪/ activity_vertical_margin
        机器人:以下属性来=@扪/ activity_horizo​​ntal_margin
        机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
        机器人:paddingTop =@扪/ activity_vertical_margin
        工具:上下文=MainActivity。&GT;

        &LT;的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=@字符串/ drawer_text/&GT;
    &LT; / RelativeLayout的&GT;

    &LT;! - 导航抽屉 - &GT;

    &LT;的ListView
        机器人:ID =@ + ID /抽屉
        机器人:layout_width =320dp
        机器人:layout_height =match_parent
        机器人:layout_gravity =开始
        机器人:后台=#F3F3F4
        机器人:choiceMode =singleChoice
        机器人:分隔=@机器人:彩色/透明
        机器人:dividerHeight =0dp/&GT;

&LT; /android.support.v4.widget.DrawerLayout>
 

解决方案
  1. 要获得 ActionBarDrawerToggle V7正常工作,你需要从 android.support.v7.app.ActionBarActivity
  2. appcompat-V7
  3. ActionBarActivity V7必须用 Theme.AppCompat 使用主题:21 支持库
  4. 除非你想从动作条切换到工具栏不要添加&LT;项目名称=windowActionBar&GT;假&LT; /项目&GT; 延伸时, Theme.AppCompat 。这样做会让你的 ActionBarActivity 没有默认动作条的装饰,和 getSupportActionBar 将返回null。您需要提供自己的工具栏并调用 setSupportActionBar 第一次使 getSupportActionBar 的工作。

Following the answer in this question i have replaced ActionBarDrawerToggle of support v4 library that in latest update(rev 21) has been deprecated with the latest ActionBarDrawerToggle of support-v7 library.

Now the drawer works on Andrid Lollipop Emulator without deprecation warnings but when I test the app on a Jelly Bean real device no drawer and no toggle drawer button is shown.

What the hell appened with this support library update? How could I fix this issue without downgrade to previous version?

Here my layout

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!--  content view -->

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/drawer_text" />
    </RelativeLayout>

    <!-- nav drawer -->

    <ListView
        android:id="@+id/drawer"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#F3F3F4"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

解决方案

  1. To get ActionBarDrawerToggle v7 to work properly you need to extends your Activity class from android.support.v7.app.ActionBarActivity
  2. ActionBarActivity v7 must be used with Theme.AppCompat theme from the appcompat-v7:21 support library.
  3. Unless you want to switch from ActionBar to ToolBar, don't add <item name="windowActionBar">false</item> when extending Theme.AppCompat. Doing so will make your ActionBarActivity have no default ActionBar decor, and getSupportActionBar will return null. You'll need to provide your own ToolBar and call setSupportActionBar first to make getSupportActionBar work.

这篇关于更换pcated android.support.v4.app.ActionBarDrawerToggle与support.v7版本的原因抽屉里不是果冻豆的作品去$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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