Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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/>

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>

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top