コード例 #1
0
ファイル: MainActivity.cs プロジェクト: Calculator88/SescTool
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.main);
            Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            _appbarLoading = FindViewById <LinearLayout>(Resource.Id.toolbar_loading_panel);
            SetSupportActionBar(toolbar);

            _drawer         = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            _navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
            _navigationView.NavigationItemSelected += OnNavigationItemSelected;

            var toggle = new ActionBarDrawerToggle(this, _drawer, toolbar, Resource.String.open, Resource.String.close);

            _drawer.AddDrawerListener(toggle);
            _drawer.SetStatusBarBackgroundColor(ContextCompat.GetColor(this, Resource.Color.primary_dark));
            toggle.SyncState();

            _navigationView.SetCheckedItem(Resource.Id.nav_class_schedule);

            var transaction = SupportFragmentManager.BeginTransaction();

            if (SupportFragmentManager.FindFragmentByTag("class") == null)
            {
                transaction.Add(Resource.Id.schedule_fragment_container, new ClassScheduleFragment(), "class");
            }
            if (SupportFragmentManager.FindFragmentByTag("classroom") == null)
            {
                transaction.Add(Resource.Id.schedule_fragment_container, new ClassroomScheduleFragment(), "classroom");
            }
            transaction.CommitNow();

            var activeFragment = bundle?.GetInt(ActiveFragmentTag, 0) ?? 0;

            switch (activeFragment)
            {
            case ClassSchedule:
                OnClassScheduleSelected();
                break;

            case TeacherSchedule:
                OnTeacherScheduleSelected();
                break;

            case ClassroomSchedule:
                OnClassroomScheduleSelected();
                break;
            }
        }
コード例 #2
0
        private void InitDrawerlayout()
        {
            MenuTitles   = Resources.GetStringArray(Resource.Array.menu_items);
            drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);

            ActionBarDrawerToggle = new MyActionBarDrawerToggle(this, drawerLayout, Resource.String.menu, Resource.String.league);
            drawerLayout.AddDrawerListener(ActionBarDrawerToggle);
            drawerLayout.SetStatusBarBackgroundColor(Resource.Color.primary_dark);

            ActionBarDrawerToggle.SyncState();

            FindViewById <NavigationView>(Resource.Id.drawerNavigationView).NavigationItemSelected += NavigationDrawerItemSelected;

            MenuOpened = true;
        }
コード例 #3
0
        public void Setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar)
        {
            fragmentContainerView = Activity.FindViewById(fragmentId);
            DrawerLayout          = drawerLayout;
            drawerLayout.SetStatusBarBackgroundColor(Resources.GetColor(Resource.Color.myPrimaryDarkColor));

            ActionBarDrawerToggle = new MyActionBarDrawerToggle(Activity, drawerLayout, toolbar, Resource.String.drawer_open, Resource.String.drawer_close)
            {
                OnDrawerClosedCallback = (view) => {
                    if (IsAdded)
                    {
                        return;
                    }
                    Activity.InvalidateOptionsMenu();
                },
                OnDrawerOpenedCallback = (view) => {
                    if (!IsAdded)
                    {
                        return;
                    }
                    if (!userLearnedDrawer)
                    {
                        userLearnedDrawer = true;
                        SaveSharedSetting(Activity, PrefUserLearnedDrawer, "true");
                    }

                    Activity.InvalidateOptionsMenu();
                }
            };

            if (!userLearnedDrawer && !fromSavedInstanceState)
            {
                drawerLayout.OpenDrawer(fragmentContainerView);
            }

            drawerLayout.Post(ActionBarDrawerToggle.SyncState);

            drawerLayout.SetDrawerListener(ActionBarDrawerToggle);
        }
コード例 #4
0
        /**
         * Android4.4以上的状态栏着色(针对于DrawerLayout)
         * 注:
         * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
         * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
         *
         * @param activity       Activity对象
         * @param drawerLayout   DrawerLayout对象
         * @param statusBarColor 状态栏颜色
         * @param alpha          透明栏透明度[0.0-1.0]
         */
        public static void TintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout, int statusBarColor, float alpha)
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.Kitkat)
            {
                return;
            }

            Window    window      = activity.Window;             //.getWindow();
            ViewGroup decorView   = (ViewGroup)window.DecorView; // ();
            ViewGroup drawContent = (ViewGroup)drawerLayout.GetChildAt(0);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                window.ClearFlags(WindowManagerFlags.TranslucentStatus);       // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); // WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.SetStatusBarColor(Color.Transparent);
                drawerLayout.SetStatusBarBackgroundColor(statusBarColor);
                int systemUiVisibility = (int)window.DecorView.SystemUiVisibility;             // getDecorView().getSystemUiVisibility();

                systemUiVisibility |= (int)SystemUiFlags.Fullscreen;                           //  View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
                systemUiVisibility |= (int)SystemUiFlags.LayoutStable;                         // View.SYSTEM_UI_FLAG_LAYOUT_STABLE;

                window.DecorView.SystemUiVisibility = (StatusBarVisibility)systemUiVisibility; // getDecorView().setSystemUiVisibility(systemUiVisibility);
            }
            else
            {
                window.AddFlags(WindowManagerFlags.TranslucentStatus);// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
            SetStatusBar(decorView, statusBarColor, true, true);
            SetTranslucentView(decorView, alpha);
            drawerLayout.SetFitsSystemWindows(false);
            drawContent.SetFitsSystemWindows(true);
            ViewGroup drawer = (ViewGroup)drawerLayout.GetChildAt(1);

            drawer.SetFitsSystemWindows(false);
        }