开发者

SlidingDrawer not working

开发者 https://www.devze.com 2023-02-21 01:54 出处:网络
In my app I have implemented the SlidingDrawer and it is not working. Am I wrong in any place. Drawer = (SlidingDrawer) findViewById(R.id.drawer);

In my app I have implemented the SlidingDrawer and it is not working. Am I wrong in any place.

Drawer = (SlidingDrawer) findViewById(R.id.drawer);


    Drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

        @Override
        public void onDrawerOpened() {
            Toast.makeText(getApplicationContext(),"Drawer Opened", Toast.LENGTH_SHORT).show();             
        }
    });

similarly the setOnDrawerCloseListener is also not working and my XML file is:

<SlidingDrawer android:id="@+id/drawer"
        android:background="@null" android:layout_height="fill_parent"
        android:handle="@+id/handle" android:content="@+id/chat_history_container"
        android:layout_width="fill_parent">
        <ImageView android:id="@+id/handle" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:src="@drawable/chat_icon" />

        <RelativeLayout android:id="@+id/chat_histo开发者_如何学运维ry_container"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            //Some TextViews here

        </RelativeLayout>
</SlidingDrawer>


Try this Code : Xml Code :

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:gravity="bottom"         
    android:background="@drawable/androidpeople">
<SlidingDrawer android:layout_width="wrap_content" 
    android:id="@+id/SlidingDrawer"     
    android:handle="@+id/slideHandleButton"   android:content="@+id/contentLayout"    
    android:padding="10dip" android:layout_height="250dip">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"   
    android:id="@+id/slideHandleButton" android:background="@drawable/closearrow">
</Button>
<LinearLayout android:layout_width="wrap_content" android:id="@+id/contentLayout" android:orientation="vertical" android:gravity="center|top" android:padding="10dip" android:background="#C0C0C0" android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>

Java Code :

public class slidingDrawerExample extends Activity {
 Button slideHandleButton;
 SlidingDrawer slidingDrawer;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
  slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
   slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
    slideHandleButton.setBackgroundResource(R.drawable.openarrow);
}
});
    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
     @Override
  public void onDrawerClosed() {
    slideHandleButton.setBackgroundResource(R.drawable.closearrow);
}
 });
 }
}

Check this Link for Reference Sliding Drawer...

0

精彩评论

暂无评论...
验证码 换一张
取 消