更换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
问题描述
继<一个答案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:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent&GT;
&LT;! - 内容视图 - &GT;
&LT; RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:以下属性来=@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_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>
- 要获得
ActionBarDrawerToggle
V7正常工作,你需要从android.support.v7.app.ActionBarActivity $ C扩展你的Activity类$ C>
从 -
ActionBarActivity
V7必须用Theme.AppCompat
使用主题:21 - 除非你想从
动作条
切换到工具栏
,不要添加&LT;项目名称=windowActionBar&GT;假&LT; /项目&GT;
延伸时,Theme.AppCompat
。这样做会让你的ActionBarActivity
没有默认动作条
的装饰,和getSupportActionBar
将返回null。您需要提供自己的工具栏
并调用setSupportActionBar
第一次使getSupportActionBar
的工作。
appcompat-V7
支持库
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>
- To get
ActionBarDrawerToggle
v7 to work properly you need to extends your Activity class fromandroid.support.v7.app.ActionBarActivity
ActionBarActivity
v7 must be used withTheme.AppCompat
theme from theappcompat-v7:21
support library.- Unless you want to switch from
ActionBar
toToolBar
, don't add<item name="windowActionBar">false</item>
when extendingTheme.AppCompat
. Doing so will make yourActionBarActivity
have no defaultActionBar
decor, andgetSupportActionBar
will return null. You'll need to provide your ownToolBar
and callsetSupportActionBar
first to makegetSupportActionBar
work.
这篇关于更换pcated android.support.v4.app.ActionBarDrawerToggle与support.v7版本的原因抽屉里不是果冻豆的作品去$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!