11

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 Android 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>
Axifive
  • 1,159
  • 2
  • 19
  • 31
AndreaF
  • 11,975
  • 27
  • 102
  • 168
  • can you show your layout? new ActionBarDrawerToggle works fine for me – nikis Oct 19 '14 at 09:42
  • see the update to the question – AndreaF Oct 19 '14 at 13:12
  • please try to subclass from ActionBarActivity instead of FragmentActivity. – nikis Oct 19 '14 at 14:05
  • I have tried to replace all `FragmentActivity` with `ActionBarActivity` but app crashes with this error `You need to use a Theme.AppCompat theme (or descendant) with this activity.` could you give me more details? – AndreaF Oct 19 '14 at 16:24
  • yep, please take a look here http://antonioleiva.com/material-design-everywhere/ and here https://chris.banes.me/2014/10/17/appcompat-v21/ – nikis Oct 19 '14 at 16:44
  • I have also tried to add AppCompact Theme as parent theme but `mybar = this.getActionBar();` get a null value and activity crashes – AndreaF Oct 19 '14 at 16:49
  • @nikis I have tried the sample in your link but navigation drawer button dowsn't appears. also in api21 I'm not able to enable drawer button – AndreaF Oct 19 '14 at 16:59
  • you should use get/setSupportActionBar instead if you are using ActionBarActivity, works fine for me with NavigationDrawer. If it doesn't work, please post updated code of your activity – nikis Oct 19 '14 at 17:08
  • I have follwed all suggestions, now the ActionBar and drawer appear but all styles are ignored and I cannot change the action bar colors, also the commands to enable images or define the number of icons to show seem ignored, all icon buttons go in overflow menu – AndreaF Oct 19 '14 at 17:17
  • setting action bar color works fine for me, I'm not sure what might be the source of issue – nikis Oct 19 '14 at 17:39
  • you use the stile.xml file to set the color? – AndreaF Oct 19 '14 at 17:52
  • yes, with parent theme Theme.AppCompat.Light.NoActionBar – nikis Oct 20 '14 at 05:08
  • If you use ActionBarActivity are you also forced to have to use the support version of Fragment since ActionBarActivity extends FragmentActivity? – Daniel Ochoa Oct 20 '14 at 16:57
  • I use the support version of Fragment (I don't know if there is a better alternative) extend ActionBar use AppCompat, added a style.xml that extends AppCompat but all my color setting are ignored and all the menu items are shown in overflow menu also if some menu items are set as always visible :( – AndreaF Oct 20 '14 at 22:46

1 Answers1

6
  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.
mindex
  • 1,606
  • 13
  • 18