Commit b48d20dfbd69f03fa8b555af59a43f78e70dde73
1 parent
7485281a
Exists in
yxb_dev
and in
2 other branches
no message
Showing
3 changed files
with
70 additions
and
2 deletions
Show diff stats
app/src/main/AndroidManifest.xml
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | android:supportsRtl="true" |
| 46 | 46 | android:theme="@style/AppTheme"> |
| 47 | 47 | |
| 48 | - <activity android:name=".ui.activity.LoginAndRegistActivity"> | |
| 48 | + <activity android:name=".ui.MainActivity"> | |
| 49 | 49 | <intent-filter> |
| 50 | 50 | <action android:name="android.intent.action.MAIN" /> |
| 51 | 51 | |
| ... | ... | @@ -54,6 +54,9 @@ |
| 54 | 54 | </activity> |
| 55 | 55 | <!--<activity android:name=".ui.activity.LoginAndRegistActivity" />--> |
| 56 | 56 | <activity android:name=".ui.activity.StartActivity"></activity> |
| 57 | + <activity android:name=".ui.activity.LoginAndRegistActivity" | |
| 58 | + android:screenOrientation="portrait" | |
| 59 | + /> | |
| 57 | 60 | </application> |
| 58 | 61 | |
| 59 | 62 | </manifest> |
| 60 | 63 | \ No newline at end of file | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/MainActivity.java
| 1 | 1 | package com.shunzhi.parent.ui; |
| 2 | 2 | |
| 3 | 3 | import android.os.Bundle; |
| 4 | +import android.support.annotation.NonNull; | |
| 4 | 5 | import android.support.design.widget.BottomNavigationView; |
| 6 | +import android.support.v4.app.Fragment; | |
| 7 | +import android.support.v4.app.FragmentTransaction; | |
| 8 | +import android.view.MenuItem; | |
| 5 | 9 | |
| 6 | 10 | import com.share.mvpsdk.base.activity.BaseCompatActivity; |
| 7 | 11 | import com.share.mvpsdk.helper.BottomNavigationViewHelper; |
| 8 | 12 | import com.shunzhi.parent.R; |
| 13 | +import com.shunzhi.parent.ui.fragment.CePingFragment; | |
| 14 | +import com.shunzhi.parent.ui.fragment.ConsultFragment; | |
| 15 | +import com.shunzhi.parent.ui.fragment.MineFragment; | |
| 16 | +import com.shunzhi.parent.ui.fragment.ReportFragment; | |
| 9 | 17 | |
| 10 | 18 | import butterknife.BindView; |
| 11 | 19 | |
| 12 | 20 | public class MainActivity extends BaseCompatActivity { |
| 13 | 21 | |
| 14 | - @BindView(R.id.bottom_navigationView) | |
| 15 | 22 | BottomNavigationView bottom_navigationView; |
| 16 | 23 | |
| 24 | + CePingFragment cePingFragment = null; | |
| 25 | + | |
| 26 | + ConsultFragment consultFragment = null; | |
| 27 | + | |
| 28 | + ReportFragment reportFragment = null; | |
| 29 | + | |
| 30 | + MineFragment mineFragment = null; | |
| 31 | + | |
| 32 | + Fragment[] fragments = null; | |
| 33 | + | |
| 34 | + private int CEPING_INDEX = 0, CONSULT_INDEX = 1, REPORT_INDEX = 2, MINE_INDEX = 3; | |
| 35 | + | |
| 36 | + | |
| 17 | 37 | @Override |
| 18 | 38 | protected void initView(Bundle savedInstanceState) { |
| 19 | 39 | |
| 40 | + bottom_navigationView = findViewById(R.id.bottom_navigationView); | |
| 41 | + | |
| 20 | 42 | BottomNavigationViewHelper.disableShiftMode(bottom_navigationView); |
| 21 | 43 | |
| 22 | 44 | bottom_navigationView.setSelectedItemId(R.id.bottom_navigationView); |
| 45 | + bottom_navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { | |
| 46 | + @Override | |
| 47 | + public boolean onNavigationItemSelected(@NonNull MenuItem item) { | |
| 48 | + switch (item.getItemId()) { | |
| 49 | + case R.id.menu_item_index://测评页面 | |
| 50 | + showFragment(CEPING_INDEX); | |
| 51 | + break; | |
| 52 | + case R.id.menu_item_consult://咨询频道 | |
| 53 | + showFragment(CONSULT_INDEX); | |
| 54 | + break; | |
| 55 | + case R.id.menu_item_report://报告 | |
| 56 | + showFragment(REPORT_INDEX); | |
| 57 | + break; | |
| 58 | + case R.id.menu_item_mine://个人中心 | |
| 59 | + showFragment(MINE_INDEX); | |
| 60 | + break; | |
| 61 | + } | |
| 62 | + return false; | |
| 63 | + } | |
| 64 | + }); | |
| 65 | + | |
| 66 | + initFragments(); | |
| 67 | + } | |
| 68 | + | |
| 69 | + private void initFragments() { | |
| 70 | + fragments = new Fragment[4]; | |
| 71 | + cePingFragment = new CePingFragment(); | |
| 72 | + consultFragment = new ConsultFragment(); | |
| 73 | + reportFragment = new ReportFragment(); | |
| 74 | + mineFragment = new MineFragment(); | |
| 75 | + fragments[CEPING_INDEX] = cePingFragment; | |
| 76 | + fragments[CONSULT_INDEX] = consultFragment; | |
| 77 | + fragments[REPORT_INDEX] = reportFragment; | |
| 78 | + fragments[MINE_INDEX] = mineFragment; | |
| 79 | + } | |
| 23 | 80 | |
| 81 | + private void showFragment(int index) { | |
| 82 | + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | |
| 83 | + for (int i = 0; i < fragments.length; i++) { | |
| 84 | + if (index == i) fragmentTransaction.show(fragments[index]); | |
| 85 | + else fragmentTransaction.hide(fragments[i]); | |
| 86 | + } | |
| 87 | + fragmentTransaction.commit(); | |
| 24 | 88 | } |
| 25 | 89 | |
| 26 | 90 | @Override | ... | ... |
app/src/main/res/layout/activity_main.xml
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | android:background="@color/window_background_light" |
| 20 | 20 | android:id="@+id/bottom_navigationView" |
| 21 | 21 | android:layout_gravity="bottom" |
| 22 | + app:menu="@menu/bottom_navigationview" | |
| 22 | 23 | ></android.support.design.widget.BottomNavigationView> |
| 23 | 24 | |
| 24 | 25 | </FrameLayout> | ... | ... |