SideDrawerToggle Setup

5 posts, 1 answers
  1. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 16 Dec 2015 Link to this post

    There's not much documentation and the example doesn't include anything on how to setup the SideDrawerToggle so I'm wondering if I can get just a quick setup process and then I can customize/tweek it to my needs. This is how my current onCreate looks, just not sure what to do with the drawerToggle after it's created. 

     

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_dashboard);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
     
            //create the side drawer
            RadSideDrawer drawer = new RadSideDrawer(this);
            drawer.setMainContent(R.layout.activity_dashboard);
            drawer.setDrawerContent(R.layout.side_drawer_content);
            drawer.setDrawerLocation(DrawerLocation.LEFT);
            drawer.setDrawerTransition(new SlideAlongTransition());
            //add the side drawer to a toggle button
            SideDrawerToggle drawerToggle = new SideDrawerToggle(drawer, toolbar);
     
     
        }

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 21 Dec 2015 Link to this post

    Hi Sal,

    Thank you for your question.

    You don't need to do anything with the toggle after you create it. The usage of the toggle is to link your side drawer with a toolbar. This will cause an automatic addition of the button to the toolbar that will be used for opening of the side drawer. What you can customize is the resource used for that button through the toogle's setDrawerOpenIcon method. If you don't change that resource, the default will be used.

    I hope this information helps.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 11 Jan in reply to Todor Link to this post

    Thanks for the reply Todor, but I'm still having some issues getting the side drawer to work within my application. I don't know if it's due to my setup or if I'm missing a step somewhere so I'll l just post everything I have right now. 

     

    First this is the XML for the main activity (I'm using the AppBarLayout that was auto-generated with this Activity) 

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".Dashboard.DashboardActivity">
     
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">
     
            <android.support.v7.widget.Toolbar
                android:id="@+id/dashboard_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay">
     
            <ImageButton
                android:id="@+id/dashboard_settings_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_settings"
                android:contentDescription="@string/settings_image"
                android:layout_gravity="right"
                android:background="@null"
                android:tint="@color/whiteColor"
                android:paddingRight="5dp"
                android:paddingLeft="5dp"/>
            </android.support.v7.widget.Toolbar>
     
            <android.support.design.widget.TabLayout
                android:id="@+id/dashboard_tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabIndicatorColor="@color/whiteColor"
                app:tabIndicatorHeight="4dp"
                />
     
        </android.support.design.widget.AppBarLayout>
     
        <include layout="@layout/content_dashboard" />
     
        <com.ensi.mobilerep.CustomViewPager
            android:id="@+id/dashboard_view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior = "@string/appbar_scrolling_view_behavior"/>
     
     
    </android.support.design.widget.CoordinatorLayout>

    this is the corresponding content xml file as well : 

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".Dashboard.DashboardActivity"
        tools:showIn="@layout/activity_dashboard">
     
    </RelativeLayout>

     

    Then here's the xml for the side menu (right now it just has 2 text views but once I get it working it would most likely contain a ListView)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
     
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Option 1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Option 2"/>
     
    </LinearLayout>
     

    And then finally here is the entire onCreate method from the main Activity where I'm trying to add the side drawer 

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_dashboard);
            //set the activity
            thisActivity = this;
            //set the fragment manager
            fragmentManager = getSupportFragmentManager();
            //setup tool bar
            Toolbar toolbar = (Toolbar) findViewById(R.id.dashboard_toolbar);
            setSupportActionBar(toolbar);
            //setup the view pager
            viewPager = (CustomViewPager) findViewById(R.id.dashboard_view_pager);
            //setup the Tab layout
            tabLayout = (TabLayout) findViewById(R.id.dashboard_tab_layout);
            //add the side menu
            final RadSideDrawer sideDrawer = new RadSideDrawer(this);
            sideDrawer.setMainContent(R.layout.content_dashboard);
            sideDrawer.setDrawerContent(R.layout.side_drawer_content);
            sideDrawer.setDrawerLocation(DrawerLocation.LEFT);
            sideDrawer.setDrawerTransition(new PushTransition());
            sideDrawer.setDrawerSize((int) Util.getDimen(TypedValue.COMPLEX_UNIT_DIP, 300));
            sideDrawer.addChangeListener(new DrawerChangeListener() {
                @Override
                public boolean onDrawerOpening(RadSideDrawer radSideDrawer) {
                    return false;
                }
     
                @Override
                public void onDrawerOpened(RadSideDrawer radSideDrawer) {
     
                }
     
                @Override
                public boolean onDrawerClosing(RadSideDrawer radSideDrawer) {
                    return false;
                }
     
                @Override
                public void onDrawerClosed(RadSideDrawer radSideDrawer) {
     
                }
            });
            new SideDrawerToggle(sideDrawer, toolbar);
            //add the settings button actions
            ImageButton settingButton = (ImageButton)findViewById(R.id.dashboard_settings_button);
            settingButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.d("message", "the settings button was pressed");
                }
            });
          }

     

    So with all of this I do get the hamburger icon in my Toolbar and it looks like it's accepting touches but the menu never opens, so it's probably me putting it in the wrong spot but I can't figure out where I'm going wrong. Thanks. 

     

     

     

  5. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 14 Jan Link to this post

    Hi Sal,

    Here's what's missing.

    RadSideDrawer is a View that needs to be added to the layout in order to be visible. It will also hold another two View-s - one for its main content, and one for the drawer content. You can either add the drawer in some of your layout files, or simply set the drawer as content of the activity. Using the latter, here's the updated version of your onCreate method:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        final RadSideDrawer sideDrawer = new RadSideDrawer(this);
        sideDrawer.setMainContent(R.layout.activity_main);
        sideDrawer.setDrawerContent(R.layout.side_layout);
        sideDrawer.setDrawerLocation(DrawerLocation.LEFT);
        sideDrawer.setDrawerTransition(new PushTransition());
        sideDrawer.setDrawerSize((int) Util.getDimen(TypedValue.COMPLEX_UNIT_DIP, 300));
     
        setContentView(sideDrawer);
     
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
         
        new SideDrawerToggle(sideDrawer, toolbar);
     
    }

    I hope this information helps. Let us know if you need further assistance.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 14 Jan in reply to Todor Link to this post

    Thanks Todor, that was the step that I was missing and it's working fine now. 
Back to Top
DevCraft banner