├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kevin │ │ └── tech │ │ └── bottomnavigationbarforandroid │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── kevin │ │ │ └── tech │ │ │ └── bottomnavigationbarforandroid │ │ │ ├── Constants.java │ │ │ ├── MainActivity.java │ │ │ ├── NightModeHelper.java │ │ │ ├── adapter │ │ │ ├── TabLayoutFragment2Adapter.java │ │ │ └── TabLayoutFragmentAdapter.java │ │ │ ├── fragment │ │ │ ├── NavigationFragment.java │ │ │ ├── RadioFragment.java │ │ │ ├── TabLayoutFragment.java │ │ │ ├── TabLayoutFragment2.java │ │ │ ├── TextTabFragment.java │ │ │ └── subfragment │ │ │ │ ├── HomeFragment.java │ │ │ │ ├── LikeFragment.java │ │ │ │ ├── LocationFragment.java │ │ │ │ └── PersonFragment.java │ │ │ └── utils │ │ │ └── SnackBarUtils.java │ └── res │ │ ├── color │ │ └── bg_drawer_navigation.xml │ │ ├── drawable-xhdpi │ │ └── notification.png │ │ ├── drawable-xxhdpi │ │ ├── capricornus.png │ │ ├── capricornus_selected.png │ │ ├── home.png │ │ ├── home_fill.png │ │ ├── libra.png │ │ ├── libra_selected.png │ │ ├── like.png │ │ ├── like_fill.png │ │ ├── location.png │ │ ├── location_fill.png │ │ ├── person.png │ │ ├── person_fill.png │ │ ├── pisces.png │ │ ├── pisces_selected.png │ │ ├── tab_host.png │ │ ├── virgo.png │ │ └── virgo_selected.png │ │ ├── drawable │ │ ├── bg_drawer_navigation_four.xml │ │ ├── bg_drawer_navigation_one.xml │ │ ├── bg_drawer_navigation_three.xml │ │ ├── bg_drawer_navigation_two.xml │ │ ├── icon_header_image.jpg │ │ ├── radiobutton_bg_home.xml │ │ ├── radiobutton_bg_like.xml │ │ ├── radiobutton_bg_location.xml │ │ ├── radiobutton_bg_me.xml │ │ └── shape_msg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_layout.xml │ │ ├── drawer_navigation_badge.xml │ │ ├── fragment_bottom_navigation_bar.xml │ │ ├── fragment_content.xml │ │ ├── fragment_radio_group.xml │ │ ├── fragment_sub_content.xml │ │ ├── fragment_tablayout.xml │ │ ├── fragment_text_tab.xml │ │ ├── layout_navigation_header.xml │ │ ├── layout_tab_view.xml │ │ └── tab_layout_for_bottom.xml │ │ ├── menu │ │ ├── menu.xml │ │ └── menu_navigation.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-night-v21 │ │ └── styles.xml │ │ ├── values-night │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── kevin │ └── tech │ └── bottomnavigationbarforandroid │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | C:\Users\Administrator\AppData\Roaming\Subversion 48 | 49 | 50 | 51 | 52 | 53 | 1.8 54 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "com.kevin.tech.bottomnavigationbarforandroid" 8 | minSdkVersion 17 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.0.1' 28 | testCompile 'junit:junit:4.12' 29 | compile 'com.ashokvarma.android:bottom-navigation-bar:1.3.1' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | -keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | public *; 17 | } 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/kevin/tech/bottomnavigationbarforandroid/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.kevin.tech.bottomnavigationbarforandroid", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/Constants.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid; 2 | 3 | /** 4 | * Created by Kevin on 2016/11/28. 5 | * Blog:http://blog.csdn.net/student9128 6 | * Description: 7 | */ 8 | 9 | public class Constants { 10 | public static final String ARGS = "args"; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.design.widget.NavigationView; 6 | import android.support.design.widget.Snackbar; 7 | import android.support.v4.app.FragmentTransaction; 8 | import android.support.v4.content.ContextCompat; 9 | import android.support.v4.view.GravityCompat; 10 | import android.support.v4.widget.DrawerLayout; 11 | import android.support.v7.app.ActionBarDrawerToggle; 12 | import android.support.v7.app.AppCompatActivity; 13 | import android.support.v7.widget.Toolbar; 14 | import android.util.Log; 15 | import android.view.Menu; 16 | import android.view.MenuItem; 17 | import android.view.View; 18 | import android.widget.LinearLayout; 19 | import android.widget.TextView; 20 | 21 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.NavigationFragment; 22 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.RadioFragment; 23 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.TabLayoutFragment; 24 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.TabLayoutFragment2; 25 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.TextTabFragment; 26 | import com.kevin.tech.bottomnavigationbarforandroid.utils.SnackBarUtils; 27 | 28 | public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener { 29 | private DrawerLayout mDrawerLayout; 30 | private Toolbar mToolbar; 31 | private NavigationView mNavigationView; 32 | private ActionBarDrawerToggle mDrawerToggle; 33 | private NavigationFragment mNavigationFragment; 34 | private RadioFragment mRadioFragment; 35 | private LinearLayout mRadioBadge;//the badge for radioGroup menu 36 | private TextView mRadioMsg; 37 | private TextTabFragment mTextTabFragment; 38 | private TabLayoutFragment mTabLayoutFragment; 39 | private TabLayoutFragment2 mTabLayoutFragment2; 40 | private NightModeHelper mNightModeHelper; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | // AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); 46 | mNightModeHelper = new NightModeHelper(this, R.style.BaseTheme); 47 | setContentView(R.layout.activity_main); 48 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 49 | mToolbar = (Toolbar) findViewById(R.id.tool_bar); 50 | mNavigationView = (NavigationView) findViewById(R.id.navigation_view); 51 | 52 | setSupportActionBar(mToolbar); 53 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 54 | 55 | mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_layout_open, R.string.drawer_layout_close); 56 | mDrawerToggle.syncState(); 57 | mDrawerToggle.setDrawerIndicatorEnabled(true); 58 | mDrawerLayout.setDrawerListener(mDrawerToggle); 59 | mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); 60 | 61 | View headerView = mNavigationView.getHeaderView(0); 62 | headerView.setOnClickListener(this); 63 | mNavigationView.setItemIconTintList(null); 64 | mNavigationView.setNavigationItemSelectedListener(this); 65 | mNavigationView.setItemTextColor(ContextCompat.getColorStateList(this, R.color.bg_drawer_navigation)); 66 | mNavigationView.setItemIconTintList(ContextCompat.getColorStateList(this, R.color.bg_drawer_navigation)); 67 | // mRadioBadge = (LinearLayout) mNavigationView.getMenu().findItem(R.id.menu_radio_group).getActionView(); 68 | // mRadioMsg = (TextView) mRadioBadge.findViewById(R.id.msg); 69 | // mRadioMsg.setText("8"); 70 | setNavigationViewChecked(0); 71 | setCurrentFragment(); 72 | 73 | } 74 | 75 | private void setNavigationViewChecked(int position) { 76 | mNavigationView.getMenu().getItem(position).setChecked(true); 77 | Log.i("Kevin", "the count of menu item is--->" + mNavigationView.getMenu().size() + ""); 78 | for (int i = 0; i < mNavigationView.getMenu().size(); i++) { 79 | if (i != position) { 80 | mNavigationView.getMenu().getItem(i).setChecked(false); 81 | } 82 | } 83 | } 84 | 85 | private void setCurrentFragment() { 86 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 87 | mNavigationFragment = NavigationFragment.newInstance(getString(R.string.navigation_navigation_bar)); 88 | transaction.replace(R.id.frame_content, mNavigationFragment).commit(); 89 | } 90 | 91 | @Override 92 | public boolean onNavigationItemSelected(@NonNull MenuItem item) { 93 | android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 94 | switch (item.getItemId()) { 95 | case R.id.menu_bottom_navigation_bar: 96 | if (mNavigationFragment == null) { 97 | mNavigationFragment = NavigationFragment.newInstance(getString(R.string.navigation_navigation_bar)); 98 | } 99 | transaction.replace(R.id.frame_content, mNavigationFragment); 100 | Snackbar.make(mDrawerLayout, "NavigationBar", Snackbar.LENGTH_SHORT).show(); 101 | setNavigationViewChecked(0); 102 | break; 103 | case R.id.menu_radio_group: 104 | if (mRadioFragment == null) { 105 | mRadioFragment = RadioFragment.newInstance(getString(R.string.navigation_radio_bar)); 106 | } 107 | transaction.replace(R.id.frame_content, mRadioFragment); 108 | // Snackbar.make(mDrawerLayout, "RadioGroup", Snackbar.LENGTH_SHORT).show(); 109 | SnackBarUtils.showSnackBar(mDrawerLayout, getString(R.string.navigation_radio_bar), this); 110 | setNavigationViewChecked(1); 111 | break; 112 | case R.id.menu_text_view: 113 | if (mTextTabFragment == null) { 114 | mTextTabFragment = TextTabFragment.newInstance(getString(R.string.navigation_text_tab)); 115 | } 116 | transaction.replace(R.id.frame_content, mTextTabFragment); 117 | Snackbar.make(mDrawerLayout, "TextView + LinearLayout", Snackbar.LENGTH_SHORT).show(); 118 | setNavigationViewChecked(2); 119 | break; 120 | case R.id.menu_tab_layout: 121 | if(mTabLayoutFragment == null){ 122 | mTabLayoutFragment = TabLayoutFragment.newInstance(getString(R.string.navigation_tab_layout)); 123 | } 124 | transaction.replace(R.id.frame_content, mTabLayoutFragment); 125 | setNavigationViewChecked(3); 126 | Snackbar.make(mDrawerLayout, "TabLayout + ViewPager", Snackbar.LENGTH_SHORT).show(); 127 | break; 128 | case R.id.menu_tab_layout2: 129 | if (mTabLayoutFragment2 == null) { 130 | mTabLayoutFragment2 = TabLayoutFragment2.newInstance(getString(R.string.navigation_tab_layout2)); 131 | } 132 | transaction.replace(R.id.frame_content, mTabLayoutFragment2); 133 | setNavigationViewChecked(4); 134 | Snackbar.make(mDrawerLayout, "TabLayout + ViewPager 2", Snackbar.LENGTH_SHORT).show(); 135 | break; 136 | 137 | 138 | } 139 | mDrawerLayout.closeDrawers(); 140 | transaction.commit(); 141 | return true; 142 | } 143 | 144 | @Override 145 | public void onClick(View view) { 146 | 147 | } 148 | 149 | @Override 150 | public boolean onCreateOptionsMenu(Menu menu) { 151 | getMenuInflater().inflate(R.menu.menu, menu); 152 | return true; 153 | } 154 | 155 | @Override 156 | public boolean onOptionsItemSelected(MenuItem item) { 157 | switch (item.getItemId()) { 158 | case R.id.home: 159 | mDrawerLayout.openDrawer(GravityCompat.START); 160 | return true; 161 | case R.id.settings: 162 | Snackbar.make(mDrawerLayout, "Settings", Snackbar.LENGTH_SHORT).show(); 163 | return true; 164 | case R.id.share: 165 | mNightModeHelper.toggle(); 166 | // Configuration newConfig = new Configuration(getResources().getConfiguration()); 167 | // newConfig.uiMode &= ~Configuration.UI_MODE_NIGHT_MASK; 168 | // newConfig.uiMode |= uiNightMode; 169 | // getResources().updateConfiguration(newConfig, null); 170 | // recreate(); 171 | return true; 172 | } 173 | return super.onOptionsItemSelected(item); 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/NightModeHelper.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid; 2 | import android.app.Activity; 3 | import android.content.SharedPreferences; 4 | import android.content.res.Configuration; 5 | import android.preference.PreferenceManager; 6 | 7 | import java.lang.ref.WeakReference; 8 | 9 | 10 | public class NightModeHelper 11 | { 12 | 13 | private static final String PREF_KEY = "nightModeState"; 14 | 15 | private static int sUiNightMode = Configuration.UI_MODE_NIGHT_UNDEFINED; 16 | 17 | private WeakReference mActivity; 18 | 19 | private SharedPreferences mPrefs; 20 | 21 | 22 | public NightModeHelper(Activity activity) 23 | { 24 | 25 | int currentMode = (activity.getResources().getConfiguration() 26 | .uiMode & Configuration.UI_MODE_NIGHT_MASK); 27 | mPrefs = PreferenceManager.getDefaultSharedPreferences(activity); 28 | init(activity, -1, mPrefs.getInt(PREF_KEY, currentMode)); 29 | } 30 | 31 | 32 | public NightModeHelper(Activity activity, int theme) 33 | { 34 | 35 | int currentMode = (activity.getResources().getConfiguration() 36 | .uiMode & Configuration.UI_MODE_NIGHT_MASK); 37 | mPrefs = PreferenceManager.getDefaultSharedPreferences(activity); 38 | init(activity, theme, mPrefs.getInt(PREF_KEY, currentMode)); 39 | } 40 | 41 | 42 | public NightModeHelper(Activity activity, int theme, int defaultUiMode) 43 | { 44 | 45 | init(activity, theme, defaultUiMode); 46 | } 47 | 48 | private void init(Activity activity, int theme, int defaultUiMode) 49 | { 50 | 51 | mActivity = new WeakReference(activity); 52 | if (sUiNightMode == Configuration.UI_MODE_NIGHT_UNDEFINED) 53 | { 54 | sUiNightMode = defaultUiMode; 55 | } 56 | updateConfig(sUiNightMode); 57 | 58 | if (theme != -1) 59 | { 60 | activity.setTheme(theme); 61 | } 62 | } 63 | 64 | private void updateConfig(int uiNightMode) 65 | { 66 | 67 | Activity activity = mActivity.get(); 68 | if (activity == null) 69 | { 70 | throw new IllegalStateException("Activity went away?"); 71 | } 72 | Configuration newConfig = new Configuration(activity.getResources().getConfiguration()); 73 | newConfig.uiMode &= ~Configuration.UI_MODE_NIGHT_MASK; 74 | newConfig.uiMode |= uiNightMode; 75 | activity.getResources().updateConfiguration(newConfig, null); 76 | sUiNightMode = uiNightMode; 77 | if (mPrefs != null) 78 | { 79 | mPrefs.edit() 80 | .putInt(PREF_KEY, sUiNightMode) 81 | .apply(); 82 | } 83 | } 84 | 85 | public static int getUiNightMode() 86 | { 87 | 88 | return sUiNightMode; 89 | } 90 | 91 | public void toggle() 92 | { 93 | 94 | if (sUiNightMode == Configuration.UI_MODE_NIGHT_YES) 95 | { 96 | notNight(); 97 | } else 98 | { 99 | night(); 100 | } 101 | } 102 | 103 | 104 | public void notNight() 105 | { 106 | 107 | updateConfig(Configuration.UI_MODE_NIGHT_NO); 108 | System.gc(); 109 | System.runFinalization(); 110 | System.gc(); 111 | mActivity.get().recreate(); 112 | } 113 | 114 | public void night() 115 | { 116 | 117 | updateConfig(Configuration.UI_MODE_NIGHT_YES); 118 | System.gc(); 119 | System.runFinalization(); // added in https://github.com/android/platform_frameworks_base/commit/6f3a38f3afd79ed6dddcef5c83cb442d6749e2ff 120 | System.gc(); 121 | mActivity.get().recreate(); 122 | } 123 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/adapter/TabLayoutFragment2Adapter.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | import android.widget.ImageView; 8 | import android.widget.LinearLayout; 9 | import android.widget.TextView; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by Kevin on 2016/11/30. 15 | * Blog:http://blog.csdn.net/student9128 16 | * Description: adapter for ViewPager of TabLayoutFragment 17 | */ 18 | 19 | public class TabLayoutFragment2Adapter extends FragmentPagerAdapter { 20 | private List mTabList; 21 | private Context mContext; 22 | private List mFragments; 23 | private ImageView mTabIcon; 24 | private TextView mTabText; 25 | private int[] mTabImgs; 26 | private LinearLayout mTabView; 27 | 28 | public TabLayoutFragment2Adapter(FragmentManager fm) { 29 | super(fm); 30 | } 31 | 32 | public TabLayoutFragment2Adapter(FragmentManager fm, List tabList, Context context, List fragments, int[] tabImgs) { 33 | super(fm); 34 | mTabList = tabList; 35 | mContext = context; 36 | mFragments = fragments; 37 | mTabImgs = tabImgs; 38 | } 39 | 40 | @Override 41 | public Fragment getItem(int position) { 42 | return mFragments.get(position); 43 | } 44 | 45 | @Override 46 | public int getCount() { 47 | return mTabList.size(); 48 | } 49 | 50 | @Override 51 | public CharSequence getPageTitle(int position) { 52 | return mTabList.get(position); 53 | } 54 | 55 | /** 56 | * set the tab view 57 | * 58 | * @param position 59 | * @return 60 | */ 61 | // public View getTabView(int position) { 62 | // View view = LayoutInflater.from(mContext).inflate(R.layout.layout_tab_view, null); 63 | // mTabView = (LinearLayout) view.findViewById(R.id.ll_tab_view); 64 | // mTabText = (TextView) view.findViewById(R.id.tv_tab_text); 65 | // mTabIcon = (ImageView) view.findViewById(R.id.iv_tab_icon); 66 | // mTabText.setText(mTabList.get(position)); 67 | // mTabIcon.setImageResource(mTabImgs[position]); 68 | // if (0 == position) {//the default color of item home is green 69 | // mTabText.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary)); 70 | // mTabIcon.setImageResource(R.drawable.home_fill); 71 | // } 72 | // return view; 73 | // } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/adapter/TabLayoutFragmentAdapter.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | import android.support.v4.content.ContextCompat; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import com.kevin.tech.bottomnavigationbarforandroid.R; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * Created by Kevin on 2016/11/30. 20 | * Blog:http://blog.csdn.net/student9128 21 | * Description: adapter for ViewPager of TabLayoutFragment 22 | */ 23 | 24 | public class TabLayoutFragmentAdapter extends FragmentPagerAdapter { 25 | private List mTabList; 26 | private Context mContext; 27 | private List mFragments; 28 | private ImageView mTabIcon; 29 | private TextView mTabText; 30 | private int[] mTabImgs; 31 | private LinearLayout mTabView; 32 | 33 | public TabLayoutFragmentAdapter(FragmentManager fm) { 34 | super(fm); 35 | } 36 | 37 | public TabLayoutFragmentAdapter(FragmentManager fm, List tabList, Context context, List fragments, int[] tabImgs) { 38 | super(fm); 39 | mTabList = tabList; 40 | mContext = context; 41 | mFragments = fragments; 42 | mTabImgs = tabImgs; 43 | } 44 | 45 | @Override 46 | public Fragment getItem(int position) { 47 | return mFragments.get(position); 48 | } 49 | 50 | @Override 51 | public int getCount() { 52 | return mTabList.size(); 53 | } 54 | 55 | @Override 56 | public CharSequence getPageTitle(int position) { 57 | return mTabList.get(position); 58 | } 59 | 60 | /** 61 | * set the tab view 62 | * 63 | * @param position 64 | * @return 65 | */ 66 | public View getTabView(int position) { 67 | View view = LayoutInflater.from(mContext).inflate(R.layout.layout_tab_view, null); 68 | mTabView = (LinearLayout) view.findViewById(R.id.ll_tab_view); 69 | mTabText = (TextView) view.findViewById(R.id.tv_tab_text); 70 | mTabIcon = (ImageView) view.findViewById(R.id.iv_tab_icon); 71 | mTabText.setText(mTabList.get(position)); 72 | mTabIcon.setImageResource(mTabImgs[position]); 73 | if (0 == position) {//the default color of item home is green 74 | mTabText.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary)); 75 | mTabIcon.setImageResource(R.drawable.home_fill); 76 | } 77 | return view; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/NavigationFragment.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.text.TextUtils; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | 13 | import com.ashokvarma.bottomnavigation.BottomNavigationBar; 14 | import com.ashokvarma.bottomnavigation.BottomNavigationItem; 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/28. 24 | * Blog:http://blog.csdn.net/student9128 25 | * Description: Bottom Navigation Bar by BottomNavigationBar 26 | */ 27 | 28 | public class NavigationFragment extends Fragment implements BottomNavigationBar.OnTabSelectedListener { 29 | 30 | 31 | private BottomNavigationBar mBottomNavigationBar; 32 | private HomeFragment mHomeFragment; 33 | private LocationFragment mLocationFragment; 34 | private LikeFragment mLikeFragment; 35 | private PersonFragment mPersonFragment; 36 | private TextView mTextView; 37 | 38 | public static NavigationFragment newInstance(String s) { 39 | NavigationFragment navigationFragment = new NavigationFragment(); 40 | Bundle bundle = new Bundle(); 41 | bundle.putString(Constants.ARGS, s); 42 | navigationFragment.setArguments(bundle); 43 | return navigationFragment; 44 | } 45 | 46 | @Nullable 47 | @Override 48 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 49 | View view = inflater.inflate(R.layout.fragment_bottom_navigation_bar, container, false); 50 | mTextView = (TextView) view.findViewById(R.id.activity_text_view); 51 | Bundle bundle = getArguments(); 52 | if (bundle != null) { 53 | String s = bundle.getString(Constants.ARGS); 54 | if (!TextUtils.isEmpty(s)) { 55 | mTextView.setText(s); 56 | } 57 | } 58 | mBottomNavigationBar = (BottomNavigationBar) view.findViewById(R.id.bottom_navigation_bar); 59 | mBottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC); 60 | mBottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED); 61 | 62 | mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.home_fill, getString(R.string.item_home)).setInactiveIconResource(R.drawable.home).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) 63 | .addItem(new BottomNavigationItem(R.drawable.location_fill, getString(R.string.item_location)).setInactiveIconResource(R.drawable.location).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) 64 | .addItem(new BottomNavigationItem(R.drawable.like_fill, getString(R.string.item_like)).setInactiveIconResource(R.drawable.like).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) 65 | .addItem(new BottomNavigationItem(R.drawable.person_fill, getString(R.string.item_person)).setInactiveIconResource(R.drawable.person).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) 66 | .setFirstSelectedPosition(0) 67 | .initialise(); 68 | 69 | mBottomNavigationBar.setTabSelectedListener(this); 70 | 71 | setDefaultFragment(); 72 | return view; 73 | } 74 | 75 | /** 76 | * set the default fagment 77 | *

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/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 mTabList = new ArrayList<>(); 38 | private TabLayoutFragmentAdapter mAdapter; 39 | private int[] mTabImgs = new int[]{R.drawable.home, R.drawable.location, R.drawable.like, R.drawable.person}; 40 | private List mFragments = new ArrayList<>(); 41 | 42 | public static TabLayoutFragment newInstance(String s) { 43 | TabLayoutFragment tabLayoutFragment = new TabLayoutFragment(); 44 | Bundle bundle = new Bundle(); 45 | bundle.putString(Constants.ARGS, s); 46 | tabLayoutFragment.setArguments(bundle); 47 | return tabLayoutFragment; 48 | } 49 | 50 | @Nullable 51 | @Override 52 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 53 | View view = inflater.inflate(R.layout.fragment_tablayout, container, false); 54 | mTextView = (TextView) view.findViewById(R.id.activity_text_view); 55 | Bundle bundle = getArguments(); 56 | if (bundle != null) { 57 | String s = bundle.getString(Constants.ARGS); 58 | if (!TextUtils.isEmpty(s)) { 59 | mTextView.setText(s); 60 | } 61 | } 62 | mViewPager = (ViewPager) view.findViewById(R.id.view_pager); 63 | mTabLayout = (TabLayout) view.findViewById(R.id.tab_layout); 64 | initTabList(); 65 | mAdapter = new TabLayoutFragmentAdapter(getChildFragmentManager(), mTabList, getActivity(), mFragments, mTabImgs); 66 | mViewPager.setAdapter(mAdapter); 67 | mViewPager.setCurrentItem(0); 68 | mTabLayout.setupWithViewPager(mViewPager); 69 | mTabLayout.setTabMode(TabLayout.MODE_FIXED); 70 | for (int i = 0; i < mTabLayout.getTabCount(); i++) { 71 | mTabLayout.getTabAt(i).setCustomView(mAdapter.getTabView(i)); 72 | } 73 | mTabLayout.addOnTabSelectedListener(this); 74 | // mViewPager.setCurrentItem(0); 75 | // mTabLayout.getTabAt(0).setIcon(R.drawable.home); 76 | // mTabLayout.getTabAt(1).setIcon(R.drawable.location); 77 | // mTabLayout.getTabAt(2).setIcon(R.drawable.like); 78 | // mTabLayout.getTabAt(3).setIcon(R.drawable.person); 79 | // setDefaultFragment(); 80 | return view; 81 | } 82 | 83 | @Override 84 | public void onStart() { 85 | super.onStart(); 86 | initFragmentList(); 87 | } 88 | 89 | private void setDefaultFragment() { 90 | getChildFragmentManager().beginTransaction() 91 | .replace(R.id.sub_content, HomeFragment.newInstance(getString(R.string.item_home))) 92 | .commit(); 93 | } 94 | 95 | /** 96 | * add Fragment 97 | */ 98 | public void initFragmentList() { 99 | mFragments.clear(); 100 | mFragments.add(HomeFragment.newInstance(getString(R.string.item_home))); 101 | mFragments.add(LocationFragment.newInstance(getString(R.string.item_location))); 102 | mFragments.add(LikeFragment.newInstance(getString(R.string.item_like))); 103 | mFragments.add(PersonFragment.newInstance(getString(R.string.item_person))); 104 | 105 | } 106 | 107 | /** 108 | * init the tab list. 109 | */ 110 | private void initTabList() { 111 | mTabList.clear(); 112 | mTabList.add(getString(R.string.item_home)); 113 | mTabList.add(getString(R.string.item_location)); 114 | mTabList.add(getString(R.string.item_like)); 115 | mTabList.add(getString(R.string.item_person)); 116 | } 117 | 118 | @Override 119 | public void onTabSelected(TabLayout.Tab tab) { 120 | setTabSelectedState(tab); 121 | } 122 | 123 | @Override 124 | public void onTabUnselected(TabLayout.Tab tab) { 125 | setTabUnSelectedState(tab); 126 | } 127 | 128 | 129 | @Override 130 | public void onTabReselected(TabLayout.Tab tab) { 131 | 132 | } 133 | 134 | private void setTabSelectedState(TabLayout.Tab tab) { 135 | View customView = tab.getCustomView(); 136 | TextView tabText = (TextView) customView.findViewById(R.id.tv_tab_text); 137 | ImageView tabIcon = (ImageView) customView.findViewById(R.id.iv_tab_icon); 138 | tabText.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); 139 | String s = tabText.getText().toString(); 140 | if (getString(R.string.item_home).equals(s)) { 141 | tabIcon.setImageResource(R.drawable.home_fill); 142 | } else if (getString(R.string.item_location).equals(s)) { 143 | tabIcon.setImageResource(R.drawable.location_fill); 144 | } else if (getString(R.string.item_like).equals(s)) { 145 | tabIcon.setImageResource(R.drawable.like_fill); 146 | } else if (getString(R.string.item_person).equals(s)) { 147 | tabIcon.setImageResource(R.drawable.person_fill); 148 | } 149 | } 150 | 151 | private void setTabUnSelectedState(TabLayout.Tab tab) { 152 | View customView = tab.getCustomView(); 153 | TextView tabText = (TextView) customView.findViewById(R.id.tv_tab_text); 154 | ImageView tabIcon = (ImageView) customView.findViewById(R.id.iv_tab_icon); 155 | tabText.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_1)); 156 | String s = tabText.getText().toString(); 157 | if (getString(R.string.item_home).equals(s)) { 158 | tabIcon.setImageResource(R.drawable.home); 159 | } else if (getString(R.string.item_location).equals(s)) { 160 | tabIcon.setImageResource(R.drawable.location); 161 | } else if (getString(R.string.item_like).equals(s)) { 162 | tabIcon.setImageResource(R.drawable.like); 163 | } else if (getString(R.string.item_person).equals(s)) { 164 | tabIcon.setImageResource(R.drawable.person); 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/TabLayoutFragment2.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.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.ImageView; 15 | import android.widget.TextView; 16 | 17 | import com.kevin.tech.bottomnavigationbarforandroid.Constants; 18 | import com.kevin.tech.bottomnavigationbarforandroid.R; 19 | import com.kevin.tech.bottomnavigationbarforandroid.adapter.TabLayoutFragment2Adapter; 20 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.HomeFragment; 21 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LikeFragment; 22 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.LocationFragment; 23 | import com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment.PersonFragment; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * Created by Kevin on 2016/11/30. 30 | * Blog:http://blog.csdn.net/student9128 31 | * Description: Bottom Navigation Bar by TabLayout. 32 | */ 33 | 34 | public class TabLayoutFragment2 extends Fragment implements TabLayout.OnTabSelectedListener { 35 | private ViewPager mViewPager; 36 | private TabLayout mTabLayout; 37 | private TextView mTextView; 38 | private List mTabList = new ArrayList<>(); 39 | private TabLayoutFragment2Adapter mAdapter; 40 | private int[] mTabImgs = new int[]{R.drawable.home, R.drawable.location, R.drawable.like, R.drawable.person}; 41 | private List mFragments = new ArrayList<>(); 42 | 43 | public static TabLayoutFragment2 newInstance(String s) { 44 | TabLayoutFragment2 tabLayoutFragment = new TabLayoutFragment2(); 45 | Bundle bundle = new Bundle(); 46 | bundle.putString(Constants.ARGS, s); 47 | tabLayoutFragment.setArguments(bundle); 48 | return tabLayoutFragment; 49 | } 50 | 51 | @Nullable 52 | @Override 53 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 54 | View view = inflater.inflate(R.layout.fragment_tablayout, container, false); 55 | mTextView = (TextView) view.findViewById(R.id.activity_text_view); 56 | Bundle bundle = getArguments(); 57 | if (bundle != null) { 58 | String s = bundle.getString(Constants.ARGS); 59 | if (!TextUtils.isEmpty(s)) { 60 | mTextView.setText(s); 61 | } 62 | } 63 | mViewPager = (ViewPager) view.findViewById(R.id.view_pager); 64 | mTabLayout = (TabLayout) view.findViewById(R.id.tab_layout); 65 | initTabList(); 66 | mAdapter = new TabLayoutFragment2Adapter(getChildFragmentManager(), mTabList, getActivity(), mFragments, mTabImgs); 67 | mViewPager.setAdapter(mAdapter); 68 | mViewPager.setCurrentItem(0); 69 | mTabLayout.setupWithViewPager(mViewPager); 70 | mTabLayout.setTabMode(TabLayout.MODE_FIXED); 71 | // for (int i = 0; i < mTabLayout.getTabCount(); i++) { 72 | // mTabLayout.getTabAt(i).setCustomView(mAdapter.getTabView(i)); 73 | // } 74 | mTabLayout.addOnTabSelectedListener(this); 75 | // mViewPager.setCurrentItem(0); 76 | mTabLayout.getTabAt(0).setIcon(R.drawable.home_fill); 77 | mTabLayout.getTabAt(1).setIcon(R.drawable.location); 78 | mTabLayout.getTabAt(2).setIcon(R.drawable.like); 79 | mTabLayout.getTabAt(3).setIcon(R.drawable.person); 80 | // resetTabIcon(); 81 | // setDefaultFragment(); 82 | return view; 83 | } 84 | 85 | @Override 86 | public void onStart() { 87 | super.onStart(); 88 | initFragmentList(); 89 | } 90 | 91 | private void setDefaultFragment() { 92 | getChildFragmentManager().beginTransaction() 93 | .replace(R.id.sub_content, HomeFragment.newInstance(getString(R.string.item_home))) 94 | .commit(); 95 | } 96 | 97 | /** 98 | * add Fragment 99 | */ 100 | public void initFragmentList() { 101 | mFragments.clear(); 102 | mFragments.add(HomeFragment.newInstance(getString(R.string.item_home))); 103 | mFragments.add(LocationFragment.newInstance(getString(R.string.item_location))); 104 | mFragments.add(LikeFragment.newInstance(getString(R.string.item_like))); 105 | mFragments.add(PersonFragment.newInstance(getString(R.string.item_person))); 106 | 107 | } 108 | 109 | /** 110 | * init the tab list. 111 | */ 112 | private void initTabList() { 113 | mTabList.clear(); 114 | mTabList.add(getString(R.string.item_home)); 115 | mTabList.add(getString(R.string.item_location)); 116 | mTabList.add(getString(R.string.item_like)); 117 | mTabList.add(getString(R.string.item_person)); 118 | } 119 | 120 | @Override 121 | public void onTabSelected(TabLayout.Tab tab) { 122 | // setTabSelectedState(tab); 123 | resetTabIcon(); 124 | int position = tab.getPosition(); 125 | Log.e("Kevin", "position--->" + position); 126 | switch (position) { 127 | case 0: 128 | tab.setIcon(R.drawable.home_fill); 129 | break; 130 | case 1: 131 | tab.setIcon(R.drawable.location_fill); 132 | break; 133 | case 2: 134 | tab.setIcon(R.drawable.like_fill); 135 | break; 136 | case 3: 137 | tab.setIcon(R.drawable.person_fill); 138 | break; 139 | 140 | } 141 | } 142 | 143 | private void resetTabIcon() { 144 | mTabLayout.getTabAt(0).setIcon(R.drawable.home); 145 | mTabLayout.getTabAt(1).setIcon(R.drawable.location); 146 | mTabLayout.getTabAt(2).setIcon(R.drawable.like); 147 | mTabLayout.getTabAt(3).setIcon(R.drawable.person); 148 | } 149 | 150 | @Override 151 | public void onTabUnselected(TabLayout.Tab tab) { 152 | // setTabUnSelectedState(tab); 153 | } 154 | 155 | 156 | @Override 157 | public void onTabReselected(TabLayout.Tab tab) { 158 | 159 | } 160 | 161 | private void setTabSelectedState(TabLayout.Tab tab) { 162 | View customView = tab.getCustomView(); 163 | TextView tabText = (TextView) customView.findViewById(R.id.tv_tab_text); 164 | ImageView tabIcon = (ImageView) customView.findViewById(R.id.iv_tab_icon); 165 | tabText.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); 166 | String s = tabText.getText().toString(); 167 | if (getString(R.string.item_home).equals(s)) { 168 | tabIcon.setImageResource(R.drawable.home_fill); 169 | } else if (getString(R.string.item_location).equals(s)) { 170 | tabIcon.setImageResource(R.drawable.location_fill); 171 | } else if (getString(R.string.item_like).equals(s)) { 172 | tabIcon.setImageResource(R.drawable.like_fill); 173 | } else if (getString(R.string.item_person).equals(s)) { 174 | tabIcon.setImageResource(R.drawable.person_fill); 175 | } 176 | } 177 | 178 | private void setTabUnSelectedState(TabLayout.Tab tab) { 179 | View customView = tab.getCustomView(); 180 | TextView tabText = (TextView) customView.findViewById(R.id.tv_tab_text); 181 | ImageView tabIcon = (ImageView) customView.findViewById(R.id.iv_tab_icon); 182 | tabText.setTextColor(ContextCompat.getColor(getActivity(), R.color.black_1)); 183 | String s = tabText.getText().toString(); 184 | if (getString(R.string.item_home).equals(s)) { 185 | tabIcon.setImageResource(R.drawable.home); 186 | } else if (getString(R.string.item_location).equals(s)) { 187 | tabIcon.setImageResource(R.drawable.location); 188 | } else if (getString(R.string.item_like).equals(s)) { 189 | tabIcon.setImageResource(R.drawable.like); 190 | } else if (getString(R.string.item_person).equals(s)) { 191 | tabIcon.setImageResource(R.drawable.person); 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /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/subfragment/HomeFragment.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.kevin.tech.bottomnavigationbarforandroid.Constants; 12 | import com.kevin.tech.bottomnavigationbarforandroid.R; 13 | 14 | /** 15 | * Created by Kevin on 2016/11/28. 16 | * Blog:http://blog.csdn.net/student9128 17 | * Description: HomeFragment 18 | */ 19 | 20 | public class HomeFragment extends Fragment{ 21 | public static HomeFragment newInstance(String s){ 22 | HomeFragment homeFragment = new HomeFragment(); 23 | Bundle bundle = new Bundle(); 24 | bundle.putString(Constants.ARGS,s); 25 | homeFragment.setArguments(bundle); 26 | return homeFragment; 27 | } 28 | 29 | @Nullable 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 32 | View view = inflater.inflate(R.layout.fragment_sub_content, container, false); 33 | Bundle bundle = getArguments(); 34 | String s = bundle.getString(Constants.ARGS); 35 | TextView textView = (TextView) view.findViewById(R.id.fragment_text_view); 36 | textView.setText(s); 37 | return view; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/subfragment/LikeFragment.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.kevin.tech.bottomnavigationbarforandroid.Constants; 12 | import com.kevin.tech.bottomnavigationbarforandroid.R; 13 | 14 | /** 15 | * Created by Kevin on 2016/11/28. 16 | * Blog:http://blog.csdn.net/student9128 17 | * Description: 18 | */ 19 | 20 | public class LikeFragment extends Fragment{ 21 | public static LikeFragment newInstance(String s){ 22 | LikeFragment homeFragment = new LikeFragment(); 23 | Bundle bundle = new Bundle(); 24 | bundle.putString(Constants.ARGS,s); 25 | homeFragment.setArguments(bundle); 26 | return homeFragment; 27 | } 28 | 29 | @Nullable 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 32 | View view = inflater.inflate(R.layout.fragment_sub_content, container, false); 33 | Bundle bundle = getArguments(); 34 | String s = bundle.getString(Constants.ARGS); 35 | TextView textView = (TextView) view.findViewById(R.id.fragment_text_view); 36 | textView.setText(s); 37 | return view; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/subfragment/LocationFragment.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.kevin.tech.bottomnavigationbarforandroid.Constants; 12 | import com.kevin.tech.bottomnavigationbarforandroid.R; 13 | 14 | /** 15 | * Created by Kevin on 2016/11/28. 16 | * Blog:http://blog.csdn.net/student9128 17 | * Description: 18 | */ 19 | 20 | public class LocationFragment extends Fragment{ 21 | public static LocationFragment newInstance(String s){ 22 | LocationFragment homeFragment = new LocationFragment(); 23 | Bundle bundle = new Bundle(); 24 | bundle.putString(Constants.ARGS,s); 25 | homeFragment.setArguments(bundle); 26 | return homeFragment; 27 | } 28 | 29 | @Nullable 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 32 | View view = inflater.inflate(R.layout.fragment_sub_content, container, false); 33 | Bundle bundle = getArguments(); 34 | String s = bundle.getString(Constants.ARGS); 35 | TextView textView = (TextView) view.findViewById(R.id.fragment_text_view); 36 | textView.setText(s); 37 | return view; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/fragment/subfragment/PersonFragment.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.fragment.subfragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.kevin.tech.bottomnavigationbarforandroid.Constants; 12 | import com.kevin.tech.bottomnavigationbarforandroid.R; 13 | 14 | /** 15 | * Created by Kevin on 2016/11/28. 16 | * Blog:http://blog.csdn.net/student9128 17 | * Description: 18 | */ 19 | 20 | public class PersonFragment extends Fragment{ 21 | public static PersonFragment newInstance(String s){ 22 | PersonFragment homeFragment = new PersonFragment(); 23 | Bundle bundle = new Bundle(); 24 | bundle.putString(Constants.ARGS,s); 25 | homeFragment.setArguments(bundle); 26 | return homeFragment; 27 | } 28 | 29 | @Nullable 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 32 | View view = inflater.inflate(R.layout.fragment_sub_content, container, false); 33 | Bundle bundle = getArguments(); 34 | String s = bundle.getString(Constants.ARGS); 35 | TextView textView = (TextView) view.findViewById(R.id.fragment_text_view); 36 | textView.setText(s); 37 | return view; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/kevin/tech/bottomnavigationbarforandroid/utils/SnackBarUtils.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid.utils; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.Snackbar; 5 | import android.support.v4.content.ContextCompat; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | 9 | import com.kevin.tech.bottomnavigationbarforandroid.R; 10 | 11 | /** 12 | * Created by Kevin on 2016/11/30. 13 | * Blog:http://blog.csdn.net/student9128 14 | * Description: 15 | */ 16 | 17 | public class SnackBarUtils { 18 | public static void showSnackBar(View view,String string, Context context) { 19 | Snackbar snackbar = Snackbar.make(view, string, Snackbar.LENGTH_SHORT); 20 | snackbar.getView().setBackgroundColor(ContextCompat.getColor(context, R.color.amber)); 21 | // setSnackbarMessageTextColor(snackbar, R.color.white); 22 | snackbar.show(); 23 | } 24 | 25 | public static void setSnackbarMessageTextColor(Snackbar snackbar, int color) { 26 | View view = snackbar.getView(); 27 | TextView textView = (TextView) view.findViewById(R.id.snackbar_text); 28 | textView.setTextColor(color); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/color/bg_drawer_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xhdpi/notification.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/capricornus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/capricornus.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/capricornus_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/capricornus_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/home.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/home_fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/home_fill.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/libra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/libra.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/libra_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/libra_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/like.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/like.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/like_fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/like_fill.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/location.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/location_fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/location_fill.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/person.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/person_fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/person_fill.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/pisces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/pisces.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/pisces_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/pisces_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_host.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/tab_host.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/virgo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/virgo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/virgo_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable-xxhdpi/virgo_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_drawer_navigation_four.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_drawer_navigation_one.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_drawer_navigation_three.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_drawer_navigation_two.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/icon_header_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/drawable/icon_header_image.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/radiobutton_bg_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/radiobutton_bg_like.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/radiobutton_bg_location.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/radiobutton_bg_me.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_msg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 22 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/drawer_navigation_badge.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_bottom_navigation_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_radio_group.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 14 | 15 | 22 | 23 | 30 | 31 | 36 | 37 | 42 | 43 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_sub_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_tablayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | 21 | 22 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_text_tab.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 24 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_navigation_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 23 | 24 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_tab_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/tab_layout_for_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 18 | 19 | 24 | 25 | 30 | 31 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 |

4 | 8 | 13 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 20 | 24 | 29 | 30 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-night-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 22 | 23 | 24 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #E51C23 4 | #D01716 5 | #E040FB 6 | #00000000 7 | #FFFF 8 | #EEEEEE 9 | #E0E0E0 10 | #000000 11 | #333333 12 | #BB9C27B0 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Navigation 3 | Open 4 | Close 5 | Blog:http://blog.csdn.net/student9128 6 | Kevin 7 | Hello 8 | NavigationBar 9 | RadioGroup 10 | TabLayout + ViewPager 11 | TabLayout + ViewPager 2 12 | TextView + LinearLayout 13 | TabHost 14 | 15 | Home 16 | Location 17 | Like 18 | Me 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 19 | 20 | 29 | 30 | 38 | 39 | 42 | 43 | 70 | 71 | 81 | 82 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 22 | 23 | 24 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #259B24 4 | #0A7E07 5 | #FF4081 6 | #00000000 7 | #FFFFFF 8 | #EEEEEE 9 | #E0E0E0 10 | #000000 11 | #333333 12 | #BBFFC107 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Navigation 3 | Open 4 | Close 5 | Blog:http://blog.csdn.net/student9128 6 | Kevin 7 | Hello 8 | NavigationBar 9 | RadioGroup 10 | TabLayout + ViewPager 11 | TabLayout + ViewPager 2 12 | TextView + LinearLayout 13 | TabHost 14 | 15 | Home 16 | Location 17 | Like 18 | Me 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 19 | 20 | 29 | 30 | 38 | 39 | 42 | 43 | 70 | 71 | 81 | 82 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /app/src/test/java/com/kevin/tech/bottomnavigationbarforandroid/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.kevin.tech.bottomnavigationbarforandroid; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/student9128/BottomNavigationBarForAndroid/1cc0df2fda92b40ce3e86b981ce63ae8353b1b7d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------