diff --git a/README-en.md b/README-en.md index c39c4fc633cf07d29c51ab27764a5d52f95add8f..2ac95c51f0abed155ed6ac1b9c5ded856804285f 100644 --- a/README-en.md +++ b/README-en.md @@ -1,8 +1,35 @@ [中文(Chinese)](https://github.com/chaychan/BottomBarLayout) +### Support + +If you feel that my project is helpful to you, please help me to click on the **star** and let more people see it. Thank you! + ### Introduction   Currently, App on the market almost has a navigation bar at the bottom, so we often need to use this during development. Although there are many tools on the github packaged bottom navigation bar, such as bottombar, alphaIndicator Swipe gradient bottom controls etc., but these controls are not particularly easy to use due to too many functions and no detailed documentation. Sometimes we just want a simple bottom navigation, but we don't want to go One by one in the layout of the LinearLayout or RadioGroup, and then change the tab icon, let ViewPager jump to the corresponding page and a series of tedious operations, this time, you can use BottomBarLayout, simply can achieve the following effect: + +#### **How to import** + +Add the jitpack repository address in allprojects{} in build.gradle in the project root directory, as follows: + + allprojects { + repositories { + jcenter() + maven { url 'https://jitpack.io' }//Add jitpack warehouse address + } + } + +Open the build.gradle in the app's module, add dependencies in dependencies {} as follows: + + dependencies { + compile 'com.github.chaychan:BottomBarLayout:1.2.0' //It is recommended to use the latest version + } + + +The latest version can be viewed + +[https://github.com/chaychan/BottomBarLayout/releases](https://github.com/chaychan/BottomBarLayout/releases) + ### Demo ![](./intro_img/display1.gif) @@ -11,6 +38,10 @@ ![](./intro_img/4.png) +### V1.1.2 update instructions (2018-12-13) + +- Support for dynamically adding and removing item + ### V1.1.2 update instructions(2018-03-20) - Add attributes to modify unread font colors and background @@ -200,6 +231,38 @@ Find the corresponding ViewPager and BottomBarLayout, set Adapter for ViewPager, This realizes the bottom navigation bar function +#### Add item dynamically + + for (int i = 0; i < mTitleIds.length; i++) { + //create item + BottomBarItem item = createBottomBarItem(i); + mBottomBarLayout.addItem(item); //addItem + + TabFragment homeFragment = createFragment(mTitleIds[i]); + mFragmentList.add(homeFragment); + } + + + private BottomBarItem createBottomBarItem(int i) { + BottomBarItem item = new BottomBarItem.Builder(this) + .titleTextSize(8) + .titleNormalColor(R.color.tab_normal_color) + .titleSelectedColor(R.color.tab_selected_color) + // .openTouchBg(false) + // .marginTop(5) + // .itemPadding(5) + // .unreadNumThreshold(99) + // .unreadTextColor(R.color.white) + + //There are still many properties, please see the methods in the Builder for details. + .create(mNormalIconIds[i], mSelectedIconIds[i], getString(mTitleIds[i])); + return item; + } + +#### Remove item + + mBottomBarLayout.removeItem(0); + #### Turn on the slide effect Tab switch between the closure of the default sliding effect, if you need to open the setSmoothScroll () method can be called by calling BottomBarLayout: @@ -267,29 +330,6 @@ Drawable is written as follows: app:notifyPointBg="@drawable/shape_notify_point" -#### **How to import** - -Add the jitpack repository address in allprojects{} in build.gradle in the project root directory, as follows: - - allprojects { - repositories { - jcenter() - maven { url 'https://jitpack.io' }//Add jitpack warehouse address - } - } - -Open the build.gradle in the app's module, add dependencies in dependencies {} as follows: - - dependencies { - compile 'com.github.chaychan:BottomBarLayout:1.1.2' //It is recommended to use the latest version - } - - -The latest version can be viewed - -[https://github.com/chaychan/BottomBarLayout/releases](https://github.com/chaychan/BottomBarLayout/releases) - - Well, here's the introduction of BottomBarLayout stop here, the reason for the package this control is mainly for the convenience of development, hope to help more people, if you have any ideas or comments may wish to put forward to me, I will continue to improve BottomBarLayout of. diff --git a/README.md b/README.md index ed4c9e1e566b64708c3dd15cb10dae1b41314bca..0b1c45e65d8ff1f3a6b6e9de7793336176dc5c0c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,45 @@ [英文(English)](https://github.com/chaychan/BottomBarLayout/blob/master/README-en.md) +### 支持 + + 如果觉得我的项目对你有所帮助的话,帮我点下**star** 吧,让更多人的人可以看到,谢谢! + ### 轻量级的底部导航栏   目前市场上的App,几乎都有底部页签导航栏,所以我们在开发的时候经常需要用到这个,虽然github上有不少已经封装好的底部导航栏的工具,例如bottombar,alphaIndicator(仿微信滑动渐变底部控件)等,但是这些控件由于功能太多,而且也没有给予详细的介绍文档,所以用起来不是特别容易,有时候我们仅仅只是想要一个简简单单的底部导航,但是又不想去自己在布局中搞一个个LinearLayout或者RadioGroup,然后切换页签的时候更换图标,让ViewPager跳转到对应的页面等一系列繁琐的操作,这时候,你可以使用BottomBarLayout,简简单单就可以实现以下效果: + +#### **导入方式** + +在项目根目录下的build.gradle中的allprojects{}中,添加jitpack仓库地址,如下: + + allprojects { + repositories { + jcenter() + maven { url 'https://jitpack.io' }//添加jitpack仓库地址 + } + } + +打开app的module中的build.gradle,在dependencies{}中,添加依赖,如下: + + dependencies { + compile 'com.github.chaychan:BottomBarLayout:1.2.0' //建议使用最新版本 + } + + +最新发布的版本可以查看 + +[https://github.com/chaychan/BottomBarLayout/releases](https://github.com/chaychan/BottomBarLayout/releases) + ![](./intro_img/display1.gif) #### 显示未读数、提示小红点、提示消息 ![](./intro_img/4.png) +### V1.2.0版本更新说明 (2018-12-13) + +- 支持动态添加、移除条目 + ### V1.1.2版本更新说明(2018-03-20) - 添加修改未读数字体颜色和背景的属性 @@ -191,6 +222,38 @@ 这样就实现底部导航栏功能了 +#### 动态添加条目 + + for (int i = 0; i < mTitleIds.length; i++) { + //创建item + BottomBarItem item = createBottomBarItem(i); + mBottomBarLayout.addItem(item); //添加条目 + + TabFragment homeFragment = createFragment(mTitleIds[i]); + mFragmentList.add(homeFragment); + } + + + private BottomBarItem createBottomBarItem(int i) { + BottomBarItem item = new BottomBarItem.Builder(this) + .titleTextSize(8) + .titleNormalColor(R.color.tab_normal_color) + .titleSelectedColor(R.color.tab_selected_color) + // .openTouchBg(false) + // .marginTop(5) + // .itemPadding(5) + // .unreadNumThreshold(99) + // .unreadTextColor(R.color.white) + + //还有很多属性,详情请查看Builder里面的方法 + .create(mNormalIconIds[i], mSelectedIconIds[i], getString(mTitleIds[i])); + return item; + } + +#### 移除条目 + + mBottomBarLayout.removeItem(0); + #### 开启滑动效果 页签之间的切换默认关闭了滑动效果,如果需要开启可以通过调用BottomBarLayout的setSmoothScroll()方法: @@ -328,29 +391,6 @@ drawable的编写如下: -#### **导入方式** - -在项目根目录下的build.gradle中的allprojects{}中,添加jitpack仓库地址,如下: - - allprojects { - repositories { - jcenter() - maven { url 'https://jitpack.io' }//添加jitpack仓库地址 - } - } - -打开app的module中的build.gradle,在dependencies{}中,添加依赖,如下: - - dependencies { - compile 'com.github.chaychan:BottomBarLayout:1.1.2' //建议使用最新版本 - } - - -最新发布的版本可以查看 - -[https://github.com/chaychan/BottomBarLayout/releases](https://github.com/chaychan/BottomBarLayout/releases) - - 好了,到这里BottomBarLayout的介绍就到此为止了,之所以封装这个控件主要是为了方便开发,希望可以帮助到更多人,如果大家有什么想法或者意见不妨向我提出,我会不断完善BottomBarLayout的。 diff --git a/apk/demo.apk b/apk/demo.apk new file mode 100644 index 0000000000000000000000000000000000000000..9ebea1b4cb5bb999d7c47d72b78e0ca2f58a44de Binary files /dev/null and b/apk/demo.apk differ diff --git a/build.gradle b/build.gradle index b78a0b86c939620b6f05483ce45c4d3ef0ef595e..e4bb1bc3003b16fe6a58b81e5c0f86d564a7c54c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,19 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.compile_sdk_version = 27 + ext.build_tools_version = "27.0.3" + + ext.min_sdk_version = 16 + ext.target_sdk_version = 27 + ext.android_support_version = "27.1.1" + repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +23,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/demo/build.gradle b/demo/build.gradle index 8837d6d7249d97d855bc6b224cca06146765aced..f5286b1cdf14d28ffc2686e580ac9ca4ebd7e26d 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,31 +1,41 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion compile_sdk_version + buildToolsVersion build_tools_version defaultConfig { applicationId "com.chaychan.bottombarlayout" - minSdkVersion 16 - targetSdkVersion 25 + minSdkVersion min_sdk_version + targetSdkVersion target_sdk_version versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } + signingConfigs { + appSign { + keyAlias KEY_ALIAS + keyPassword KEY_PASSWORD + storeFile file(KEY_FILE_PATH) + storePassword KEY_STORE_PASSWORD + } + } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.appSign } } } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + api fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.android.support.constraint:constraint-layout:1.0.1' - testCompile 'junit:junit:4.12' - compile project(':library') + api "com.android.support:appcompat-v7:$android_support_version" + api 'com.android.support.constraint:constraint-layout:1.0.1' + testImplementation 'junit:junit:4.12' + api project(':library') } diff --git a/demo/demo.jks b/demo/demo.jks new file mode 100644 index 0000000000000000000000000000000000000000..380d6f8af63d3f46a25ba15180fb7f99de20ec6e Binary files /dev/null and b/demo/demo.jks differ diff --git a/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java b/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java index ccc3102beece9b30e743e8804fd9b3f3943faef9..16c40afe80183b0d9a69027b785cca591a314da9 100644 --- a/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java +++ b/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java @@ -117,7 +117,7 @@ public class DynamicAddItemActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu, menu); + getMenuInflater().inflate(R.menu.menu_dynamic, menu); return true; } diff --git a/demo/src/main/java/com/chaychan/bottombarlayout/FragmentManagerActivity.java b/demo/src/main/java/com/chaychan/bottombarlayout/FragmentManagerActivity.java index fe8e6aca7f6b47b7f1b51ab5a2f1d1cc06ec903c..c5c829a188d6795f8c515b3ae105b2341bea8b8f 100644 --- a/demo/src/main/java/com/chaychan/bottombarlayout/FragmentManagerActivity.java +++ b/demo/src/main/java/com/chaychan/bottombarlayout/FragmentManagerActivity.java @@ -5,6 +5,8 @@ import android.os.Handler; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.FrameLayout; @@ -137,4 +139,28 @@ public class FragmentManagerActivity extends AppCompatActivity { animation.cancel(); } } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_demo, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.action_clear_unread: + mBottomBarLayout.setUnread(0, 0); + mBottomBarLayout.setUnread(1, 0); + break; + case R.id.action_clear_notify: + mBottomBarLayout.hideNotify(2); + break; + case R.id.action_clear_msg: + mBottomBarLayout.hideMsg(3); + break; + } + return super.onOptionsItemSelected(item); + } } diff --git a/demo/src/main/java/com/chaychan/bottombarlayout/ViewPagerActivity.java b/demo/src/main/java/com/chaychan/bottombarlayout/ViewPagerActivity.java index e77b0820a72d24556d05c3eec262df2d6dee164b..0fc8783b4629f0c908da02fd4cd257593321c8c2 100644 --- a/demo/src/main/java/com/chaychan/bottombarlayout/ViewPagerActivity.java +++ b/demo/src/main/java/com/chaychan/bottombarlayout/ViewPagerActivity.java @@ -8,6 +8,8 @@ import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ImageView; @@ -46,25 +48,25 @@ public class ViewPagerActivity extends AppCompatActivity { TabFragment homeFragment = new TabFragment(); Bundle bundle1 = new Bundle(); - bundle1.putString(TabFragment.CONTENT,"首页"); + bundle1.putString(TabFragment.CONTENT, "首页"); homeFragment.setArguments(bundle1); mFragmentList.add(homeFragment); TabFragment videoFragment = new TabFragment(); Bundle bundle2 = new Bundle(); - bundle2.putString(TabFragment.CONTENT,"视频"); + bundle2.putString(TabFragment.CONTENT, "视频"); videoFragment.setArguments(bundle2); mFragmentList.add(videoFragment); TabFragment microFragment = new TabFragment(); Bundle bundle3 = new Bundle(); - bundle3.putString(TabFragment.CONTENT,"微头条"); + bundle3.putString(TabFragment.CONTENT, "微头条"); microFragment.setArguments(bundle3); mFragmentList.add(microFragment); TabFragment meFragment = new TabFragment(); Bundle bundle4 = new Bundle(); - bundle4.putString(TabFragment.CONTENT,"我的"); + bundle4.putString(TabFragment.CONTENT, "我的"); meFragment.setArguments(bundle4); mFragmentList.add(meFragment); } @@ -75,10 +77,10 @@ public class ViewPagerActivity extends AppCompatActivity { mBottomBarLayout.setOnItemSelectedListener(new BottomBarLayout.OnItemSelectedListener() { @Override public void onItemSelected(final BottomBarItem bottomBarItem, int previousPosition, final int currentPosition) { - Log.i("MainActivity","position: " + currentPosition); - if (currentPosition == 0){ + Log.i("MainActivity", "position: " + currentPosition); + if (currentPosition == 0) { //如果是第一个,即首页 - if (previousPosition == currentPosition){ + if (previousPosition == currentPosition) { //如果是在原来位置上点击,更换首页图标并播放旋转动画 bottomBarItem.setSelectedIconResourceId(R.mipmap.tab_loading);//更换成加载图标 bottomBarItem.setStatus(true); @@ -104,7 +106,7 @@ public class ViewPagerActivity extends AppCompatActivity { bottomBarItem.setStatus(tabNotChanged);//刷新图标 cancelTabLoading(bottomBarItem); } - },3000); + }, 3000); return; } } @@ -117,16 +119,18 @@ public class ViewPagerActivity extends AppCompatActivity { } }); - mBottomBarLayout.setUnread(0,20);//设置第一个页签的未读数为20 - mBottomBarLayout.setUnread(1,1001);//设置第二个页签的未读数 + mBottomBarLayout.setUnread(0, 20);//设置第一个页签的未读数为20 + mBottomBarLayout.setUnread(1, 1001);//设置第二个页签的未读数 mBottomBarLayout.showNotify(2);//设置第三个页签显示提示的小红点 - mBottomBarLayout.setMsg(3,"NEW");//设置第四个页签显示NEW提示文字 + mBottomBarLayout.setMsg(3, "NEW");//设置第四个页签显示NEW提示文字 } - /**停止首页页签的旋转动画*/ + /** + * 停止首页页签的旋转动画 + */ private void cancelTabLoading(BottomBarItem bottomItem) { Animation animation = bottomItem.getImageView().getAnimation(); - if (animation != null){ + if (animation != null) { animation.cancel(); } } @@ -147,4 +151,28 @@ public class ViewPagerActivity extends AppCompatActivity { return mFragmentList.size(); } } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_demo, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.action_clear_unread: + mBottomBarLayout.setUnread(0, 0); + mBottomBarLayout.setUnread(1, 0); + break; + case R.id.action_clear_notify: + mBottomBarLayout.hideNotify(2); + break; + case R.id.action_clear_msg: + mBottomBarLayout.hideMsg(3); + break; + } + return super.onOptionsItemSelected(item); + } } diff --git a/demo/src/main/res/layout/activity_fragment_manager.xml b/demo/src/main/res/layout/activity_fragment_manager.xml index 9d0d8b4ffb7d620c3115510dc4406ebc1d9bfdaf..da6dcb2b2b2fbafb883593cd9da30012ce69d6d9 100644 --- a/demo/src/main/res/layout/activity_fragment_manager.xml +++ b/demo/src/main/res/layout/activity_fragment_manager.xml @@ -51,7 +51,7 @@ app:itemTextSize="8sp" app:itemMarginTop="-5dp" app:openTouchBg="true" - app:unreadThreshold="999" + app:unreadThreshold="99" app:touchDrawable="@drawable/selector_bg" /> diff --git a/demo/src/main/res/menu/menu_demo.xml b/demo/src/main/res/menu/menu_demo.xml new file mode 100644 index 0000000000000000000000000000000000000000..20ad3a437a20d47858d4a04e3069491493d71403 --- /dev/null +++ b/demo/src/main/res/menu/menu_demo.xml @@ -0,0 +1,19 @@ + + + + + + + + + \ No newline at end of file diff --git a/demo/src/main/res/menu/menu.xml b/demo/src/main/res/menu/menu_dynamic.xml similarity index 100% rename from demo/src/main/res/menu/menu.xml rename to demo/src/main/res/menu/menu_dynamic.xml diff --git a/gradle.properties b/gradle.properties index aac7c9b4614ccfde6c721f24994cf30885a791d0..833533c18746c3778d4ba432aebafa23f7444494 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +15,8 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +KEY_FILE_PATH=demo.jks +KEY_PASSWORD=123456 +KEY_ALIAS=demo +KEY_STORE_PASSWORD=123456 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eac3466d0f3853c8f944be8c7706dd07899ce7d3..db4f44160bf3d2417b99cf575647ff1dd5d21bfa 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index 90c8b693994126a0108f033eadcc8001cc3e05de..3a6ba59e128fa30aafcd23b76f75eb904d97d351 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion compile_sdk_version + buildToolsVersion build_tools_version defaultConfig { - minSdkVersion 16 - targetSdkVersion 25 - versionCode 1 - versionName "1.0" + minSdkVersion min_sdk_version + targetSdkVersion target_sdk_version + versionCode 5 + versionName "1.2.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -22,10 +22,10 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + api fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.3.1' - testCompile 'junit:junit:4.12' + testImplementation 'junit:junit:4.12' + api "com.android.support:appcompat-v7:$android_support_version" }