3

I am using a Navigation Drawer as shown here: Android Example. At the moment, the Actionbar is static, it does not move when the Drawer opens/closes (only it's title changes). How can I apply this effect:

Image

I want the entire ActionBar to move with the Sliding fragment. And the Name and Buttons on the ActionBar to remain as they are. Please tell me what code you would need to see.

ALSO, Question 2:

When you're using DrawerLayout you include in the xml the FrameLayout (for the content_frame) and ListView (where you add your navigation settings... In that Drawer, can you modify the layout so that you can add not just ListView but other Views aswell? On top or bottom of the ListView? Something like this:

enter image description here

I want to add ImageView (not hyperlinked, just Image) and Additional TextViews (for instructions) not hyperlinked.

KickAss
  • 4,210
  • 8
  • 33
  • 41
  • 1
    Have a look [here](http://stackoverflow.com/questions/11234375/how-did-google-manage-to-do-this-slide-actionbar-in-android-application) – Steve Benett Aug 31 '13 at 15:10
  • I will add that to my code. Please also see Question 2 on my Edit above. – KickAss Aug 31 '13 at 16:10
  • @KickAss: if possible,plz post customised code of `NavigationDrawer`, It will be helpful to others as well. – Mehul Joisar Dec 23 '13 at 07:00
  • Customised how? I now use ActionBarSherlock and SlidingMenu libraries. These both are backward compatible and very easy to implement and customise. – KickAss Dec 23 '13 at 11:09

4 Answers4

9

Consider using SlidingMenu library from GitHub. It's powerfull flexible and also you can do ANYTHING with it. You can slide the actionbar by just simply calling:

setSlidingActionBarEnabled(true);

https://github.com/jfeinstein10/SlidingMenu

Omar Farhat
  • 668
  • 4
  • 15
  • 1
    Wow if I knew of this 2 days ago, I would not have spent 2 days trying to make the Android Example work and customizing it :( – KickAss Aug 31 '13 at 21:00
  • after download this code..this code contains error. Please solve it. I got frustrated. – AnAndroid Mar 10 '14 at 12:03
  • actually there need abs library. what is that ? please solve it. please please – AnAndroid Mar 10 '14 at 12:13
  • I tried to use the sliding menu. But when slider opens the main view is not getting faded like other apps has. – Smogger Jul 18 '14 at 11:49
  • @ShashankAgarwal Make sure to add these lines : menu.setShadowWidthRes(R.dimen.shadow_width); menu.setShadowDrawable(R.drawable.shadow); menu.setBehindOffsetRes(R.dimen.slidingmenu_offset); – Omar Farhat Jul 18 '14 at 19:49
  • But that is for Sliding Menu shadow. I am talking about the main screen content that has to fade when slider menu opens. – Smogger Jul 19 '14 at 06:13
  • @omarfarhat97 very useful. Thanks – Dipali Shah Sep 20 '16 at 06:35
2

To the second point: Sure you can. The NavigationDrawer is not limited to use just the ListView. Just use a ViewGroup like a LinearLayout as the 2nd child of the DrawerLayout and put in any View you want. But keep in mind to add this line in the specification of your LinearLayout:

<LinearLayout
     ...
     android:layout_gravity="start"
     ...>

     <TextView..../>
     <ImageView...../>
<LinearLayout/>
Steve Benett
  • 12,843
  • 7
  • 59
  • 79
1

I think this is what you are looking for. This is the code from sample source code of the example you are refering.

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
Sithu
  • 4,241
  • 1
  • 20
  • 28
1

I think you can use this kind of layout to implement the some view on the top of the drawer list view..

<!-- The main content view -->

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->

<RelativeLayout
    android:id="@+id/drawerLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:background="#191919" >

    <EditText
        android:id="@+id/edit_Search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FC3A3B"
        android:hint="  Search"
        android:padding="10dp"
        android:textColor="#ffffff"
        android:textColorHint="#ffffff" >

        <requestFocus />
    </EditText>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/edit_Search"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="20dp"
        android:src="@drawable/icon_small_search" />

    <ListView
        android:id="@+id/drawer_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/edit_Search"
        android:background="#191919"
        android:choiceMode="singleChoice"
        android:divider="#000000"
        android:dividerHeight="1dp" >
    </ListView>
</RelativeLayout>

PankajSharma
  • 1,529
  • 14
  • 27