在this question中的答案后,我已替换ActionBarDrawerToggle
支持v4库,其中最新更新(rev 21)已被弃用最新ActionBarDrawerToggle
support-v7 library
。
现在抽屉在Andrid Lollipop Emulator上工作时没有弃用警告,但是当我在Jelly Bean真实设备上测试应用程序时,没有抽屉,也没有显示切换抽屉按钮。
这个支持库更新到底是什么?如果不降级到以前的版本,我怎么能解决这个问题?
这是我的布局
<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>
答案 0 :(得分:6)
ActionBarDrawerToggle
v7正常运行,您需要从android.support.v7.app.ActionBarActivity
ActionBarActivity
v7必须与Theme.AppCompat
支持库中的appcompat-v7:21
主题一起使用。ActionBar
切换到ToolBar
,否则 在扩展<item name="windowActionBar">false</item>
时添加Theme.AppCompat
。这样做会使ActionBarActivity
没有默认ActionBar
装饰,getSupportActionBar
将返回null。您需要首先提供自己的ToolBar
并致电setSupportActionBar
以使getSupportActionBar
正常工作。