private void B_confirm_Click(object sender, EventArgs e) { ProgressBar bar = FindViewById <ProgressBar>(Resource.Id.progressBar1); EditText user_id = FindViewById <EditText>(Resource.Id.editText1); EditText user_password = FindViewById <EditText>(Resource.Id.editText2); WebApi api = new WebApi(); if (user_id.Text.Trim() == "") { Toast.MakeText(this, "You must entry a valid username", ToastLength.Short).Show(); user_id.RequestFocus(); return; } if (user_password.Text.Trim() == "") { Toast.MakeText(this, "You must entry a valid password", ToastLength.Short).Show(); user_password.RequestFocus(); return; } if (api.Login(user_id.Text.Trim(), user_password.Text.Trim())) { SetContentView(Resource.Layout.menu); _drawerLayout = FindViewById <Android.Support.V4.Widget.DrawerLayout>(Resource.Id.dl_left); listview_leftMenu = FindViewById <ListView>(Resource.Id.left_menu); toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); _drawerToggle = new ActionBarDrawerToggle(this, _drawerLayout, toolbar, 0, 0);//并没有起效果性作用 string[] menus = new string[] { "首页", "博问", "闪存" }; ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleExpandableListItem1, menus); listview_leftMenu.Adapter = adapter; toolbar.Title = "Toolbar1"; SetSupportActionBar(toolbar);//设置兼容toolbar,替代原本的actionbar //SupportActionBar.SetDisplayShowHomeEnabled(true);//设置显示左上角Home图标 //SupportActionBar.SetDisplayHomeAsUpEnabled(true);//设置左上角的左箭头; 这两个必须同时为true才能显示 SupportActionBar.SetDisplayShowTitleEnabled(true); //设置不显示标题 SupportActionBar.SetHomeButtonEnabled(true); //设置返回键可用 SupportActionBar.Title = "Toolbar"; toolbar.Title = "Toolbar1"; toolbar.SetTitleTextColor(Resources.GetColor(Resource.Color.white)); _drawerLayout.SetDrawerListener(_drawerToggle); //设置侧滑监听 _drawerToggle.SyncState(); //设置左箭头与Home图标的切换与侧滑同步 StatusBarUtil.SetColorStatusBar(this); } else { bar.Visibility = ViewStates.Invisible; Toast.MakeText(this, "user name or password is not valid", ToastLength.Short).Show(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); /*tablayout*/ TabLayout tab = FindViewById <TabLayout>(Resource.Id.tabMain); tab.AddTab(tab.NewTab().SetText("小猪")); tab.AddTab(tab.NewTab().SetText("社会")); tab.AddTab(tab.NewTab().SetText("教育")); // 设置TabLayout的“长度” SetIndicator(tab, 25, 25); /*viewpage*/ var viewPager = FindViewById <ViewPager>(Resource.Id.ly_content); var mAdapter = new MyFragmentPagerAdapter(SupportFragmentManager, tab.TabCount); viewPager.Adapter = mAdapter; viewPager.CurrentItem = 0; //Tab 选择事件 tab.TabSelected += (s, e) => { viewPager.CurrentItem = e.Tab.Position; }; viewPager.AddOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tab));//关联Tablayout+Viewpager /*toolbar右侧菜单*/ Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); toolbar.InflateMenu(Resource.Menu.actionMenu); //填充actionMenu菜单项 toolbar.MenuItemClick += (s, e) => //菜单项单击事件 { if (e.Item.ItemId == Resource.Id.menu_add) { Toast.MakeText(this, "添加菜单项", ToastLength.Short).Show(); } else if (e.Item.ItemId == Resource.Id.menu_edit) { Toast.MakeText(this, "编辑菜单项", ToastLength.Short).Show(); } else { Toast.MakeText(this, "搜索菜单项", ToastLength.Short).Show(); } }; /*左菜单的list*/ ListView listview_leftMenu = FindViewById <ListView>(Resource.Id.left_menu); string[] menus = new string[] { "登录", "检查更新", "关于我们" }; ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleExpandableListItem1, menus); listview_leftMenu.Adapter = new MyCustomeAdapter(this, menus); listview_leftMenu.ItemClick += (o, e) => { if (menus[e.Position] == "检查更新") { Task startupWork = new Task(() => { ToUpDate(); }); startupWork.Start(); } }; /*左菜单呼出按钮*/ DrawerLayout drawerLayout = FindViewById <DrawerLayout>(Resource.Id.left_Active); Button ToolBarUser_button = FindViewById <Button>(Resource.Id.ToolBarUser_button); ToolBarUser_button.Click += (o, e) => { drawerLayout.OpenDrawer((int)GravityFlags.Start); }; /*登录按钮*/ Button LoginOrSign = FindViewById <Button>(Resource.Id.LoginOrSign); LoginOrSign.Click += (o, e) => { Task startupWork = new Task(() => { ToLoginOrSign(); }); startupWork.Start(); }; /*设置状态栏*/ StatusBarUtil.SetColorStatusBar(this); }