Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wenchaosong committed Mar 29, 2018
1 parent 2b2b9ca commit 16792f4
Show file tree
Hide file tree
Showing 85 changed files with 1,514 additions and 217 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
### 轻量级的底部导航栏

在原项目[PagerBottomTabStrip](https://github.com/tyzlmjj/PagerBottomTabStrip) 基础上
增加了 getItem 方法,能设置对应 position 的 tab 属性

### 实现效果图

|![horizontal](/img/demo.png "horizontal")|![vertical](/img/demo8.png "vertical")|
|![horizontal](/intro_img/demo.png "horizontal")|![vertical](/intro_img/demo8.png "vertical")|
|---|---|
|![Material 1](/img/demo1.gif "Material 1")|![Material 2](/img/demo2.gif "Material 2")|
|![Material 3](/img/demo3.gif "Material 3")|![Material 4](/img/demo4.gif "Material 4")|
|![Material 1](/intro_img/demo1.gif "Material 1")|![Material 2](/intro_img/demo2.gif "Material 2")|
|![Material 3](/intro_img/demo3.gif "Material 3")|![Material 4](/intro_img/demo4.gif "Material 4")|

### 自定义扩展例子

|Library中已经实现的一个最普通的效果|
|---|
|![PagerBottomTabStrip](/img/demo5.gif "PagerBottomTabStrip")|
|![PagerBottomTabStrip](/intro_img/demo5.gif "PagerBottomTabStrip")|

|Demo中的例子||
|---|---|
|![PagerBottomTabStrip](/img/demo7.png "PagerBottomTabStrip")|![PagerBottomTabStrip](/img/demo6.png "PagerBottomTabStrip")|
|![PagerBottomTabStrip](/intro_img/demo7.png "PagerBottomTabStrip")|![PagerBottomTabStrip](/intro_img/demo6.png "PagerBottomTabStrip")|


### 使用
Expand Down Expand Up @@ -73,6 +76,6 @@ xml文件
打开app的module中的build.gradle,在dependencies{}中,添加依赖,如下:

dependencies {
compile 'com.github.wenchaosong:bottomBar:3.0.3'
compile 'com.github.wenchaosong:bottomBar:3.0.5'
}

1 change: 1 addition & 0 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
compile 'com.android.support:design:25.3.1'
}
29 changes: 25 additions & 4 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.simple">
package="com.simple">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".MaterialDesignActivity" />

<activity android:name=".CustomActivity" />

<activity android:name=".Custom2Activity" />

<activity
android:name=".BehaviorActivity"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".HideActivity"
android:theme="@style/AppTheme.NoActionBar" />

<activity android:name=".SpecialActivity" />

<activity android:name=".VerticalActivity" />

<activity android:name=".VerticalCustomActivity" />

</application>

</manifest>
109 changes: 109 additions & 0 deletions demo/src/main/java/com/simple/BehaviorActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.simple;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bottom.NavigationController;
import com.bottom.PageNavigationView;

public class BehaviorActivity extends AppCompatActivity {

NavigationController mNavigationController;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_behavior);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

PageNavigationView pageBottomTabLayout = (PageNavigationView) findViewById(R.id.tab);

mNavigationController = pageBottomTabLayout.material()
.addItem(R.drawable.ic_restore_teal_24dp, "Recents")
.addItem(R.drawable.ic_favorite_teal_24dp, "Favorites")
.addItem(R.drawable.ic_nearby_teal_24dp, "Nearby")
.build();

ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(new TestViewPagerAdapter(getSupportFragmentManager()));

mNavigationController.setupWithViewPager(viewPager);
}

//下面几个类都是为了测试写的
private class TestViewPagerAdapter extends FragmentPagerAdapter {

public TestViewPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
return new TestFragment();
}

@Override
public int getCount() {
return mNavigationController.getItemCount();
}
}

public static class TestFragment extends Fragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.recyclerview, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.setAdapter(new TestAdapter());
recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), DividerItemDecoration.VERTICAL));
}
}

private static class TestAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
int padding = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 16, parent.getResources().getDisplayMetrics());
TextView textView = new TextView(parent.getContext());
textView.setPadding(padding, padding, padding, padding);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

return new RecyclerView.ViewHolder(textView) {
};
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

if (holder.itemView instanceof TextView) {
((TextView) holder.itemView).setText(String.valueOf(position));
}
}

@Override
public int getItemCount() {
return 100;
}
}
}
49 changes: 49 additions & 0 deletions demo/src/main/java/com/simple/Custom2Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.simple;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.bottom.NavigationController;
import com.bottom.PageNavigationView;
import com.bottom.item.BaseTabItem;
import com.simple.custom.OnlyIconItemView;
import com.simple.custom.TestRepeatTab;
import com.simple.other.MyViewPagerAdapter;

public class Custom2Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_horizontal);

PageNavigationView tab = (PageNavigationView) findViewById(R.id.tab);

NavigationController navigationController = tab.custom()
.addItem(newItem_test(R.drawable.ic_restore_gray_24dp, R.drawable.ic_restore_teal_24dp))
.addItem(newItem(R.drawable.ic_favorite_gray_24dp, R.drawable.ic_favorite_teal_24dp))
.addItem(newItem(R.drawable.ic_nearby_gray_24dp, R.drawable.ic_nearby_teal_24dp))
.build();

ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager(), navigationController.getItemCount()));

//自动适配ViewPager页面切换
navigationController.setupWithViewPager(viewPager);
}

//创建一个Item
private BaseTabItem newItem(int drawable, int checkedDrawable) {
OnlyIconItemView onlyIconItemView = new OnlyIconItemView(this);
onlyIconItemView.initialize(drawable, checkedDrawable);
return onlyIconItemView;
}

//创建一个Item(测试重复点击的方法)
private BaseTabItem newItem_test(int drawable, int checkedDrawable) {
TestRepeatTab testRepeatTab = new TestRepeatTab(this);
testRepeatTab.initialize(drawable, checkedDrawable);
return testRepeatTab;
}
}
50 changes: 50 additions & 0 deletions demo/src/main/java/com/simple/CustomActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.simple;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.bottom.NavigationController;
import com.bottom.PageNavigationView;
import com.bottom.item.BaseTabItem;
import com.bottom.item.NormalItemView;
import com.simple.other.MyViewPagerAdapter;

public class CustomActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_horizontal);

PageNavigationView tab = (PageNavigationView) findViewById(R.id.tab);

NavigationController navigationController = tab.custom()
.addItem(newItem(R.drawable.ic_restore_gray_24dp, R.drawable.ic_restore_teal_24dp, "Recents"))
.addItem(newItem(R.drawable.ic_favorite_gray_24dp, R.drawable.ic_favorite_teal_24dp, "Favorites"))
.addItem(newItem(R.drawable.ic_nearby_gray_24dp, R.drawable.ic_nearby_teal_24dp, "Nearby"))
.build();

ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager(), navigationController.getItemCount()));

//自动适配ViewPager页面切换
navigationController.setupWithViewPager(viewPager);

//设置消息数
navigationController.setMessageNumber(1, 8);

//设置显示小圆点
navigationController.setHasMessage(0, true);
}

//创建一个Item
private BaseTabItem newItem(int drawable, int checkedDrawable, String text) {
NormalItemView normalItemView = new NormalItemView(this);
normalItemView.initialize(drawable, checkedDrawable, text);
normalItemView.setTextDefaultColor(Color.GRAY);
normalItemView.setTextCheckedColor(0xFF009688);
return normalItemView;
}
}
Loading

0 comments on commit 16792f4

Please sign in to comment.