【问题标题】:How to open and close Slidedrawer with one button - android如何一键打开和关闭 Slidedrawer - android
【发布时间】:2014-04-11 02:05:53
【问题描述】:

试图用一个按钮打开和关闭滑动抽屉,但它不起作用

xml 代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/open_close_slide"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/setting" />

<SlidingDrawer
    android:id="@+id/slidingDrawer1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:content="@+id/content"
    android:handle="@+id/handle" >

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Handle" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </LinearLayout>
</SlidingDrawer>

java代码

  final SlidingDrawer slidingDrawer1 = (SlidingDrawer) findViewById(R.id.slidingDrawer1);

    Button setting = (Button) findViewById(R.id.open_close_slide);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            slidingDrawer1.open();
        // want to add another code here to close the slide 
        }
    });

如何使此按钮在第一次单击打开幻灯片并在第二次单击关闭幻灯片时双击工作?

【问题讨论】:

    标签: android double-click


    【解决方案1】:
    final SlidingDrawer slidingDrawer1 = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
    
        Button setting = (Button) findViewById(R.id.open_close_slide);
        setting.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View arg0) {
                if (slidingDrawer1.isOpened()){
                   slidingDrawer1.close();
                } 
                else{
                   slidingDrawer1.open();    
                }
    
            }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多