From d229aa809f153de9699531383ead84035456fca7 Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Fri, 16 Oct 2020 20:31:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=BF=94=E5=9B=9E=E8=87=AA?= =?UTF-8?q?=E6=AC=A7=E4=B8=9C=E5=88=87=E6=8D=A2=E5=88=B0=E5=A6=B9=E5=AD=90?= =?UTF-8?q?=E4=B8=80=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maning/gankmm/ui/activity/MainActivity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java index c4c5428..fad58bc 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java @@ -102,6 +102,8 @@ public class MainActivity extends BaseActivity implements IMainView, View.OnClic private TextView header_tv_weather; private WeatherInfoBean weatherInfoBean; + //0,1,2,3 + private int currentPosition = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -201,6 +203,9 @@ public boolean onCreateOptionsMenu(Menu menu) { * 设置默认的Fragment显示:如果savedInstanceState不是空,证明activity被后台销毁重建了,之前有fragment,就不再创建了 */ private void setDefaultFragment() { + navigationCheckedItemId = R.id.nav_girl; + navigationCheckedTitle = "妹纸"; + navigationView.setCheckedItem(navigationCheckedItemId); setMenuSelection(navigationCheckedItemId); } @@ -213,6 +218,7 @@ private void setMenuSelection(int flag) { hideFragments(fragmentTransaction); switch (flag) { case R.id.nav_girl: + currentPosition = 0; if (girlsFragment == null) { girlsFragment = GirlsFragment.newInstance(); fragmentTransaction.add(R.id.frame_content, girlsFragment); @@ -221,6 +227,7 @@ private void setMenuSelection(int flag) { } break; case R.id.nav_history: + currentPosition = 1; if (timeFragment == null) { timeFragment = HistoryFragment.newInstance(); fragmentTransaction.add(R.id.frame_content, timeFragment); @@ -229,6 +236,7 @@ private void setMenuSelection(int flag) { } break; case R.id.nav_category_ganhuo: + currentPosition = 2; if (categoryFragmentGanhuo == null) { categoryFragmentGanhuo = CategoryFragment.newInstance(Constants.Catrgory_GankHuo); fragmentTransaction.add(R.id.frame_content, categoryFragmentGanhuo); @@ -237,6 +245,7 @@ private void setMenuSelection(int flag) { } break; case R.id.nav_category_article: + currentPosition = 3; if (categoryFragmentArticle == null) { categoryFragmentArticle = CategoryFragment.newInstance(Constants.Catrgory_Article); fragmentTransaction.add(R.id.frame_content, categoryFragmentArticle); @@ -378,6 +387,11 @@ public void onBackPressed() { drawerLayout.closeDrawers(); return; } + //判断当前是不是在妹子页面 + if (currentPosition != 0) { + setDefaultFragment(); + return; + } long currtTime = System.currentTimeMillis(); if (currtTime - exitTime > 2000) { MySnackbar.makeSnackBarBlack(toolbar, getString(R.string.gank_hint_exit_app));