Sliding Drawer Example

Sliding Drawer in which we display a Sliding Drawer by using its different attributes. In this we also implement setOnDrawerOpenListener and setOnDrawerCloseListener events for changing the text of handle button.


This xml shows display one Button for the handle of SlidingDrawer and a ListView for the content of the SlidingDrawer.

Add the code for initiate the ListView, SlidingDrawer and a Button. Firstly we create String Array and then Array Adapter is used to fill the data in the list.

package com.example.cowboysmediaexample;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SlidingDrawer;

public class MainActivity extends AppCompatActivity {

    String[] stringArray = {"Aestro", "Blender", "Cupcake", "Donut", "Eclair", "Froyo", "GingerBread", "HoneyComb", "IceCream Sandwich", "JelliBean", "KitKat", "Lollipop", "MarshMallow"};

    protected void onCreate(Bundle savedInstanceState) {
        SlidingDrawer slidingDrawer = (SlidingDrawer) findViewById(; 
        final Button handleButton = (Button) findViewById(; 
        ListView simpleListView = (ListView) findViewById(; 

        ArrayAdapter arrayAdapter = new ArrayAdapter(getApplicationContext(), R.layout.list_item,, stringArray);
        simpleSlidingDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
            public void onDrawerOpened() {
        simpleSlidingDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
            public void onDrawerClosed() {