提交 c3a361a6 编写于 作者: C ccw

整理依赖库版本;添加演示Apk

上级 fbe5a5ce
[中文(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.
......
[英文(English)](https://github.com/chaychan/BottomBarLayout/blob/master/README-en.md)
### 支持
如果觉得我的项目对你有所帮助的话,帮我点下**star** 吧,让更多人的人可以看到,谢谢!
### 轻量级的底部导航栏
&emsp;&emsp;目前市场上的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的。
......
文件已添加
// 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()
}
}
......
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')
}
文件已添加
......@@ -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;
}
......
......@@ -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);
}
}
......@@ -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);
}
}
......@@ -51,7 +51,7 @@
app:itemTextSize="8sp"
app:itemMarginTop="-5dp"
app:openTouchBg="true"
app:unreadThreshold="999"
app:unreadThreshold="99"
app:touchDrawable="@drawable/selector_bg"
/>
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_clear_unread"
android:title="clearUnread"
app:showAsAction="never" />
<item
android:id="@+id/action_clear_notify"
android:title="clearNotify"
app:showAsAction="never" />
<item
android:id="@+id/action_clear_msg"
android:title="clearMsg"
app:showAsAction="never" />
</menu>
\ No newline at end of file
......@@ -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
......@@ -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
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"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册