Esempio n. 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            mToolbar = FindViewById <Toolbar>(Resource.Id.mToolbar);
            SetSupportActionBar(mToolbar);
            this.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            this.SupportActionBar.SetHomeButtonEnabled(true);

            mDrawerTitle  = this.Title;
            mPlanetTitles = this.Resources.GetStringArray(Resource.Array.planets_array);
            mDrawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            mDrawerList   = FindViewById <RecyclerView>(Resource.Id.left_drawer);

            mDrawerLayout.SetDrawerShadow(Resource.Drawable.drawer_shadow, GravityCompat.Start);
            mDrawerList.HasFixedSize = true;
            mDrawerList.SetLayoutManager(new LinearLayoutManager(this));

            mDrawerList.SetAdapter(new PlanetAdapter(mPlanetTitles, this));


            mDrawerToggle = new ActionBarDrawerToggle(
                this, mDrawerLayout, mToolbar, Resource.String.drawer_open, Resource.String.drawer_close);

            mDrawerLayout.AddDrawerListener(mDrawerToggle);

            var fragment        = AgendaFragment.NewInstance();
            var fragmentManager = this.SupportFragmentManager;
            var ft = fragmentManager.BeginTransaction();

            ft.Replace(Resource.Id.content_frame, fragment);
            ft.Commit();
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            title = drawerTitle = Title;

            drawer     = FindViewById <Android.Support.V4.Widget.DrawerLayout>(Resource.Id.drawer_layout);
            drawerList = FindViewById <ListView>(Resource.Id.left_drawer);

            drawerList.Adapter = new ArrayAdapter <string>(this, Resource.Layout.ItemMenu, Sections);

            drawerList.ItemClick += (sender, args) => ListItemClicked(args.Position);


            drawer.SetDrawerShadow(Resource.Drawable.drawer_shadow_dark, GravityCompat.End); //start



            //DrawerToggle is the animation that happens with the indicator next to the actionbar
            drawerToggle = new MyActionBarDrawerToggle(this, drawer,
                                                       Resource.Drawable.ic_drawer_light,
                                                       Resource.String.drawer_open,
                                                       Resource.String.drawer_close);

            //Display the current fragments title and update the options menu
            drawerToggle.DrawerClosed += (o, args) =>
            {
                SupportActionBar.Title = title;
                SupportInvalidateOptionsMenu();
            };

            //Display the drawer title and update the options menu
            drawerToggle.DrawerOpened += (o, args) =>
            {
                SupportActionBar.Title = drawerTitle;
                SupportInvalidateOptionsMenu();
            };

            //Set the drawer lister to be the toggle.
            drawer.SetDrawerListener(drawerToggle);



            //if first time you will want to go ahead and click first item.
            if (savedInstanceState == null)
            {
                ListItemClicked(0);
            }


            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.NavigationDrawer);

            title = drawerTitle = Title;

            drawer = FindViewById<Android.Support.V4.Widget.DrawerLayout>(Resource.Id.drawer_layout);
            drawerList = FindViewById<ListView>(Resource.Id.left_drawer);

            drawerList.Adapter = new ArrayAdapter<string>(this, Resource.Layout.ItemMenu, Sections);

            drawerList.ItemClick += (sender, args) => ListItemClicked(args.Position);


            drawer.SetDrawerShadow(Resource.Drawable.drawer_shadow_dark, GravityCompat.End); //start



            //DrawerToggle is the animation that happens with the indicator next to the actionbar
            drawerToggle = new MyActionBarDrawerToggle(this, drawer,
                                                      Resource.Drawable.ic_drawer_light,
                                                      Resource.String.drawer_open,
                                                      Resource.String.drawer_close);

            //Display the current fragments title and update the options menu
            drawerToggle.DrawerClosed += (o, args) => 
            {
                SupportActionBar.Title = title;
                SupportInvalidateOptionsMenu();
            };

            //Display the drawer title and update the options menu
            drawerToggle.DrawerOpened += (o, args) => 
            {
                SupportActionBar.Title = drawerTitle;
                SupportInvalidateOptionsMenu();
            };

            //Set the drawer lister to be the toggle.
            drawer.SetDrawerListener(drawerToggle);

            

            //if first time you will want to go ahead and click first item.
            if (savedInstanceState == null)
            {
                ListItemClicked(0);
            }


            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
        }
        public void setUp(int fragmentId, Android.Support.V4.Widget.DrawerLayout drawerLayout)
        {
            mFragmentContainerView = this.Activity.FindViewById<ListView>(fragmentId);
            mDrawerLayout = drawerLayout;
            mDrawerLayout.SetDrawerShadow(Resource.Drawable.drawer_shadow, (int)GravityFlags.Start);

            var actionBar = Activity.ActionBar; //ActionBar actionBar = getActionBar();
            actionBar.SetDisplayHomeAsUpEnabled(true);
            actionBar.SetHomeButtonEnabled(true);

            mDrawerToggle = new CustomActionBarDrawerToggle(
                this.Activity,                    /* host Activity */
                mDrawerLayout,                    /* DrawerLayout object */
                Resource.Drawable.ic_drawer,             /* nav drawer image to replace 'Up' caret */
                Resource.String.navigation_drawer_open,  /* "open drawer" description for accessibility */
                Resource.String.navigation_drawer_close  /* "close drawer" description for accessibility */
            );

            mDrawerToggle.DrawerClosed += delegate
            {
                if (! IsAdded) {
                    return;
                }
                Activity.InvalidateOptionsMenu();
            };

            mDrawerToggle.DrawerOpened += delegate
            {
                if (! IsAdded) {
                    return;
                }
                if (!mUserLearnedDrawer) {
                    mUserLearnedDrawer = true;
                    ISharedPreferences sp = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(Application.Context);
                    ISharedPreferencesEditor editor = sp.Edit();
                    editor.PutBoolean(PREF_USER_LEARNED_DRAWER, true).Apply();
                }
                Activity.InvalidateOptionsMenu();
            };

            if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
                mDrawerLayout.OpenDrawer(mFragmentContainerView);
            }

            mDrawerLayout.Post(() =>
            {
                mDrawerToggle.SyncState();
            });

            mDrawerLayout.SetDrawerListener(mDrawerToggle);
        }