user691285
user691285

Reputation: 401

How to hide handle when SlidingDrawer is open?

Is it possible to show handle when drawer is closed and hide it when drawer is open ?

I've tried overriding SlidingDrawer but had no success so far.

Upvotes: 1

Views: 2380

Answers (3)

Sunny
Sunny

Reputation: 14808

To hide the handle set the alpha to 0 and to show it set the alpha to 255.

handle.setAlpha(0); // hide

handle.setAlpha(255); // show

Upvotes: 0

vinceville
vinceville

Reputation: 319

you can use slidingdrawer's topOffset attribute with a negative value in dp. (the size of your handle) like so:

android:topOffset="-50dp"

this way when you open the sliding drawer the handle will go pass the top screen making it gone from the view. now for a cleaner look you just have to create a transparent space between the handle and the content layout of your sliding drawer. you can do this by using a linearlayout with a transparent background assigned as your slidingdrawer's "android:content" layout and put your 'real' content layout inside and assigning a topMargin to it. looks something like this:

<LinearLayout
   android:id="@+id/transparent_layout"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@color/transparent" >
     <LinearLayout
        android:id="@+id/real_content_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp" >
     </LinearLayout>
</LinearLayout>

and here's how the whole xml layout for your sliding drawer with "hiding" / "overshot" handle would look like:

<SlidingDrawer
    android:id="@+id/slidingdrawer_no_handle_when_opened"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:content="@+id/hiding_handle"
    android:handle="@+id/transparent_layout"
    android:orientation="vertical"
    android:topOffset="-50dp" >
    <LinearLayout
        android:id="@+id/hiding_handle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/buttonTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hiding Handle" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/transparent_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/transparent" >
        <LinearLayout
            android:id="@+id/real_content_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="20dp" >
        </LinearLayout>
    </LinearLayout>
</SlidingDrawer>

*note - you need to adjust the value for topOffset and topMargin n accordance to you actual layout. and you need to provide another way for the user to close the sliding drawer since your handle is hidden when opened right? ;)

Upvotes: 2

Samrakchan
Samrakchan

Reputation: 370

To hide handle button following trick worked for me

    <Button
      android:id="@+id/handle"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:background="#00000000" />

Upvotes: 2

Related Questions