├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── home.png
│ │ │ │ ├── libra.png
│ │ │ │ ├── like.png
│ │ │ │ ├── person.png
│ │ │ │ ├── pisces.png
│ │ │ │ ├── virgo.png
│ │ │ │ ├── location.png
│ │ │ │ ├── tab_host.png
│ │ │ │ ├── capricornus.png
│ │ │ │ ├── home_fill.png
│ │ │ │ ├── like_fill.png
│ │ │ │ ├── person_fill.png
│ │ │ │ ├── location_fill.png
│ │ │ │ ├── libra_selected.png
│ │ │ │ ├── pisces_selected.png
│ │ │ │ ├── virgo_selected.png
│ │ │ │ └── capricornus_selected.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── notification.png
│ │ │ ├── drawable
│ │ │ │ ├── icon_header_image.jpg
│ │ │ │ ├── radiobutton_bg_home.xml
│ │ │ │ ├── radiobutton_bg_like.xml
│ │ │ │ ├── radiobutton_bg_me.xml
│ │ │ │ ├── bg_drawer_navigation_four.xml
│ │ │ │ ├── bg_drawer_navigation_two.xml
│ │ │ │ ├── radiobutton_bg_location.xml
│ │ │ │ ├── bg_drawer_navigation_three.xml
│ │ │ │ ├── bg_drawer_navigation_one.xml
│ │ │ │ └── shape_msg.xml
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-night
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── color
│ │ │ │ └── bg_drawer_navigation.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── layout
│ │ │ │ ├── drawer_navigation_badge.xml
│ │ │ │ ├── fragment_bottom_navigation_bar.xml
│ │ │ │ ├── fragment_sub_content.xml
│ │ │ │ ├── fragment_content.xml
│ │ │ │ ├── layout_tab_view.xml
│ │ │ │ ├── tab_layout_for_bottom.xml
│ │ │ │ ├── content_layout.xml
│ │ │ │ ├── layout_navigation_header.xml
│ │ │ │ ├── fragment_tablayout.xml
│ │ │ │ ├── fragment_text_tab.xml
│ │ │ │ ├── fragment_radio_group.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── menu
│ │ │ │ ├── menu.xml
│ │ │ │ └── menu_navigation.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ └── values-night-v21
│ │ │ │ └── styles.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── kevin
│ │ │ │ └── tech
│ │ │ │ └── bottomnavigationbarforandroid
│ │ │ │ ├── Constants.java
│ │ │ │ ├── utils
│ │ │ │ └── SnackBarUtils.java
│ │ │ │ ├── fragment
│ │ │ │ ├── subfragment
│ │ │ │ │ ├── LikeFragment.java
│ │ │ │ │ ├── PersonFragment.java
│ │ │ │ │ ├── HomeFragment.java
│ │ │ │ │ └── LocationFragment.java
│ │ │ │ ├── NavigationFragment.java
│ │ │ │ ├── RadioFragment.java
│ │ │ │ ├── TextTabFragment.java
│ │ │ │ ├── TabLayoutFragment.java
│ │ │ │ └── TabLayoutFragment2.java
│ │ │ │ ├── adapter
│ │ │ │ ├── TabLayoutFragment2Adapter.java
│ │ │ │ └── TabLayoutFragmentAdapter.java
│ │ │ │ ├── NightModeHelper.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── kevin
│ │ │ └── tech
│ │ │ └── bottomnavigationbarforandroid
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── kevin
│ │ └── tech
│ │ └── bottomnavigationbarforandroid
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
78 | * the content id should not be same with the parent content id
79 | */
80 | private void setDefaultFragment() {
81 | FragmentTransaction transaction = getFragmentManager().beginTransaction();
82 | HomeFragment homeFragment = mHomeFragment.newInstance(getString(R.string.item_home));
83 | transaction.replace(R.id.sub_content, homeFragment).commit();
84 |
85 | }
86 |
87 | @Override
88 | public void onTabSelected(int position) {
89 | FragmentTransaction beginTransaction = getFragmentManager().beginTransaction();
90 |
91 | switch (position) {
92 | case 0:
93 | if (mHomeFragment == null) {
94 | mHomeFragment = HomeFragment.newInstance(getString(R.string.item_home));
95 | }
96 | beginTransaction.replace(R.id.sub_content, mHomeFragment);
97 | break;
98 | case 1:
99 | if (mLocationFragment == null) {
100 | mLocationFragment = LocationFragment.newInstance(getString(R.string.item_location));
101 | }
102 | beginTransaction.replace(R.id.sub_content, mLocationFragment);
103 | break;
104 | case 2:
105 | if (mLikeFragment == null) {
106 | mLikeFragment = LikeFragment.newInstance(getString(R.string.item_like));
107 | }
108 | beginTransaction.replace(R.id.sub_content, mLikeFragment);
109 | break;
110 | case 3:
111 | if (mPersonFragment == null) {
112 | mPersonFragment = PersonFragment.newInstance(getString(R.string.item_person));
113 | }
114 | beginTransaction.replace(R.id.sub_content, mPersonFragment);
115 | break;
116 | }
117 | beginTransaction.commit();
118 |
119 | }
120 |
121 | @Override
122 | public void onTabUnselected(int position) {
123 |
124 | }
125 |
126 | @Override
127 | public void onTabReselected(int position) {
128 |
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/RadioFragment.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v4.content.ContextCompat;
8 | import android.text.TextUtils;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.RadioButton;
13 | import android.widget.RadioGroup;
14 | import android.widget.TextView;
15 |
16 | import com.kevin.tech.bottomnavigationbarforandroid.Constants;
17 | import com.kevin.tech.bottomnavigationbarforandroid.R;
18 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.HomeFragment;
19 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LikeFragment;
20 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LocationFragment;
21 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.PersonFragment;
22 |
23 | /**
24 | * Created by Kevin on 2016/11/28.
25 | * Blog:http://blog.csdn.net/student9128
26 | * Description: Bottom Navigation Bar by RadioGroup
27 | */
28 |
29 | public class RadioFragment extends Fragment implements RadioGroup.OnCheckedChangeListener {
30 |
31 | private TextView mTextView;
32 | private RadioButton mRadioHome, mRadioLocation, mRadioLike, mRadioMe;
33 | private RadioGroup mRadioGroup;
34 | private HomeFragment mHomeFragment;
35 | private LocationFragment mLocationFragment;
36 | private LikeFragment mLikeFragment;
37 | private PersonFragment mPersonFragment;
38 |
39 | public static RadioFragment newInstance(String s) {
40 | RadioFragment radioFragment = new RadioFragment();
41 | Bundle bundle = new Bundle();
42 | bundle.putString(Constants.ARGS, s);
43 | radioFragment.setArguments(bundle);
44 | return radioFragment;
45 | }
46 |
47 | @Nullable
48 | @Override
49 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
50 | View view = inflater.inflate(R.layout.fragment_radio_group, container, false);
51 | mTextView = (TextView) view.findViewById(R.id.activity_text_view);
52 | mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
53 | mRadioHome = (RadioButton) view.findViewById(R.id.rb_home);
54 | mRadioLocation = (RadioButton) view.findViewById(R.id.rb_location);
55 | mRadioLike = (RadioButton) view.findViewById(R.id.rb_like);
56 | mRadioMe = (RadioButton) view.findViewById(R.id.rb_me);
57 | Bundle bundle = getArguments();
58 | if (bundle != null) {
59 | String s = bundle.getString(Constants.ARGS);
60 | if (!TextUtils.isEmpty(s)) {
61 | mTextView.setText(s);
62 | }
63 | }
64 | mRadioGroup.setOnCheckedChangeListener(this);
65 | return view;
66 | }
67 |
68 | @Override
69 | public void onStart() {
70 | setDefaultFragment();//写在onCreateView里面,当页面跑到其他Fragment再回来就不会生效
71 | super.onStart();
72 | }
73 |
74 | private void setDefaultFragment() {
75 | mRadioHome.setChecked(true);
76 | mRadioLocation.setChecked(false);
77 | mRadioLike.setChecked(false);
78 | mRadioMe.setChecked(false);
79 | if (mRadioHome.isChecked()) {
80 | setTabState();
81 | FragmentTransaction transaction = getFragmentManager().beginTransaction();
82 | mHomeFragment = mHomeFragment.newInstance(getString(R.string.item_home));
83 | transaction.replace(R.id.sub_content, mHomeFragment).commit();
84 | }
85 | }
86 |
87 |
88 | @Override
89 | public void onCheckedChanged(RadioGroup group, int checkId) {
90 | FragmentTransaction transaction = getFragmentManager().beginTransaction();
91 | switch (checkId) {
92 | case R.id.rb_home:
93 | if (mHomeFragment == null) {
94 | mHomeFragment = HomeFragment.newInstance(getString(R.string.item_home));
95 | }
96 | transaction.replace(R.id.sub_content, mHomeFragment);
97 | break;
98 | case R.id.rb_location:
99 | if (mLocationFragment == null) {
100 | mLocationFragment = LocationFragment.newInstance(getString(R.string.item_location));
101 | }
102 | transaction.replace(R.id.sub_content, mLocationFragment);
103 | break;
104 | case R.id.rb_like:
105 | if (mLikeFragment == null) {
106 | mLikeFragment = LikeFragment.newInstance(getString(R.string.item_like));
107 | }
108 | transaction.replace(R.id.sub_content, mLikeFragment);
109 | break;
110 | case R.id.rb_me:
111 | if (mPersonFragment == null) {
112 | mPersonFragment = PersonFragment.newInstance(getString(R.string.item_person));
113 | }
114 | transaction.replace(R.id.sub_content, mPersonFragment);
115 | break;
116 | }
117 | setTabState();
118 | transaction.commit();
119 | }
120 |
121 | private void setTabState() {
122 | setHomeState();
123 | setLocationState();
124 | setLikeState();
125 | setMeState();
126 |
127 | }
128 |
129 | /**
130 | * set tab home state
131 | */
132 | private void setHomeState() {
133 | if (mRadioHome.isChecked()) {
134 | mRadioHome.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
135 | } else {
136 | mRadioHome.setTextColor(ContextCompat.getColor(getActivity(), R.color.black));
137 | }
138 | }
139 |
140 | private void setLocationState() {
141 | if (mRadioLocation.isChecked()) {
142 | mRadioLocation.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
143 | } else {
144 | mRadioLocation.setTextColor(ContextCompat.getColor(getActivity(), R.color.black));
145 | }
146 | }
147 |
148 | private void setLikeState() {
149 | if (mRadioLike.isChecked()) {
150 | mRadioLike.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
151 | } else {
152 | mRadioLike.setTextColor(ContextCompat.getColor(getActivity(), R.color.black));
153 | }
154 | }
155 |
156 | private void setMeState() {
157 | if (mRadioMe.isChecked()) {
158 | mRadioMe.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
159 | } else {
160 | mRadioMe.setTextColor(ContextCompat.getColor(getActivity(), R.color.black));
161 | }
162 | }
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/TextTabFragment.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v4.content.ContextCompat;
8 | import android.text.TextUtils;
9 | import android.util.Log;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.TextView;
14 |
15 | import com.kevin.tech.bottomnavigationbarforandroid.Constants;
16 | import com.kevin.tech.bottomnavigationbarforandroid.R;
17 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.HomeFragment;
18 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LikeFragment;
19 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LocationFragment;
20 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.PersonFragment;
21 |
22 | /**
23 | * Created by Kevin on 2016/11/29.
24 | * Blog:http://blog.csdn.net/student9128
25 | * Description: Bottom Navigation Bar by TextView + LinearLayout.
26 | */
27 |
28 | public class TextTabFragment extends Fragment implements View.OnClickListener {
29 | private TextView mTHome, mTLocation, mTLike, mTMe, mTextView;
30 | private HomeFragment mHomeFragment;
31 | private LocationFragment mLocationFragment;
32 | private LikeFragment mLikeFragment;
33 | private PersonFragment mPersonFragment;
34 |
35 | public static TextTabFragment newInstance(String s) {
36 | TextTabFragment viewPagerFragment = new TextTabFragment();
37 | Bundle bundle = new Bundle();
38 | bundle.putString(Constants.ARGS, s);
39 | viewPagerFragment.setArguments(bundle);
40 | return viewPagerFragment;
41 | }
42 |
43 | @Nullable
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
46 | View view = inflater.inflate(R.layout.fragment_text_tab, container, false);
47 | mTextView = (TextView) view.findViewById(R.id.activity_text_view);
48 | mTHome = (TextView) view.findViewById(R.id.tv_home);
49 | mTLocation = (TextView) view.findViewById(R.id.tv_location);
50 | mTLike = (TextView) view.findViewById(R.id.tv_like);
51 | mTMe = (TextView) view.findViewById(R.id.tv_person);
52 | Log.d("Kevin", mTextView.getText().toString());
53 | Bundle bundle = getArguments();
54 | if (bundle != null) {
55 | String s = bundle.getString(Constants.ARGS);
56 | Log.i("Kevin", s + "");
57 | if (!TextUtils.isEmpty(s)) {
58 | mTextView.setText(s);
59 | }
60 | }
61 | mTHome.setOnClickListener(this);
62 | mTLocation.setOnClickListener(this);
63 | mTLike.setOnClickListener(this);
64 | mTMe.setOnClickListener(this);
65 | setDefaultFragment();
66 | return view;
67 | }
68 |
69 | /**
70 | * set the default Fragment
71 | */
72 | private void setDefaultFragment() {
73 | switchFrgment(0);
74 | //set the defalut tab state
75 | setTabState(mTHome, R.drawable.home_fill, getColor(R.color.colorPrimary));
76 | }
77 |
78 | @Override
79 | public void onClick(View view) {
80 | resetTabState();//reset the tab state
81 | switch (view.getId()) {
82 | case R.id.tv_home:
83 | setTabState(mTHome, R.drawable.home_fill, getColor(R.color.colorPrimary));
84 | switchFrgment(0);
85 | break;
86 | case R.id.tv_location:
87 | setTabState(mTLocation, R.drawable.location_fill, getColor(R.color.colorPrimary));
88 | switchFrgment(1);
89 | break;
90 | case R.id.tv_like:
91 | setTabState(mTLike, R.drawable.like_fill, getColor(R.color.colorPrimary));
92 | switchFrgment(2);
93 | break;
94 | case R.id.tv_person:
95 | setTabState(mTMe, R.drawable.person_fill, getColor(R.color.colorPrimary));
96 | switchFrgment(3);
97 | break;
98 | }
99 | }
100 |
101 | /**
102 | * switch the fragment accordting to id
103 | * @param i id
104 | */
105 | private void switchFrgment(int i) {
106 | FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
107 | switch (i) {
108 | case 0:
109 | if (mHomeFragment == null) {
110 | mHomeFragment = mHomeFragment.newInstance(getString(R.string.item_home));
111 | }
112 | transaction.replace(R.id.sub_content, mHomeFragment);
113 | break;
114 | case 1:
115 | if (mLocationFragment == null) {
116 | mLocationFragment = LocationFragment.newInstance(getString(R.string.item_location));
117 | }
118 | transaction.replace(R.id.sub_content, mLocationFragment);
119 | break;
120 | case 2:
121 | if (mLikeFragment == null) {
122 | mLikeFragment = LikeFragment.newInstance(getString(R.string.item_like));
123 | }
124 | transaction.replace(R.id.sub_content, mLikeFragment);
125 | break;
126 | case 3:
127 | if (mPersonFragment == null) {
128 | mPersonFragment = PersonFragment.newInstance(getString(R.string.item_person));
129 | }
130 | transaction.replace(R.id.sub_content, mPersonFragment);
131 | break;
132 | }
133 | transaction.commit();
134 | }
135 |
136 | /**
137 | * set the tab state of bottom navigation bar
138 | *
139 | * @param textView the text to be shown
140 | * @param image the image
141 | * @param color the text color
142 | */
143 | private void setTabState(TextView textView, int image, int color) {
144 | textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, image, 0, 0);//Call requires API level 17
145 | textView.setTextColor(color);
146 | }
147 |
148 |
149 | /**
150 | * revert the image color and text color to black
151 | */
152 | private void resetTabState() {
153 | setTabState(mTHome, R.drawable.home, getColor(R.color.black_1));
154 | setTabState(mTLocation, R.drawable.location, getColor(R.color.black_1));
155 | setTabState(mTLike, R.drawable.like, getColor(R.color.black_1));
156 | setTabState(mTMe, R.drawable.person, getColor(R.color.black_1));
157 |
158 | }
159 |
160 | /**
161 | * @param i the color id
162 | * @return color
163 | */
164 | private int getColor(int i) {
165 | return ContextCompat.getColor(getActivity(), i);
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/TabLayoutFragment.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.content.ContextCompat;
8 | import android.support.v4.view.ViewPager;
9 | import android.text.TextUtils;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import com.kevin.tech.bottomnavigationbarforandroid.Constants;
17 | import com.kevin.tech.bottomnavigationbarforandroid.R;
18 | import com.kevin.tech.bottomnavigationbarforandroid.adapter.TabLayoutFragmentAdapter;
19 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.HomeFragment;
20 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LikeFragment;
21 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LocationFragment;
22 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.PersonFragment;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | * Created by Kevin on 2016/11/30.
29 | * Blog:http://blog.csdn.net/student9128
30 | * Description: Bottom Navigation Bar by TabLayout.
31 | */
32 |
33 | public class TabLayoutFragment extends Fragment implements TabLayout.OnTabSelectedListener {
34 | private ViewPager mViewPager;
35 | private TabLayout mTabLayout;
36 | private TextView mTextView;
37 | private List