implementation'com.ashokvarma.android:bottom-navigation-bar:2.0.4'
//底部导航栏
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="@+id/bottom_navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#13BEEA"
android:layout_gravity="bottom"/>
private void InitNavigationBar(){
bottomNavigationBar.setTabSelectedListener(this);
bottomNavigationBar.setMode(BottomNavigationBar.MODE_SHIFTING);
bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE)
.setBarBackgroundColor("#24EA13")
.setActiveColor("#138CEA");
// ShapeBadgeItem badge = new ShapeBadgeItem();
// badge.setShapeColor("#EA7B13").setHideOnSelect(true).setGravity(Gravity.RIGHT | Gravity.TOP);
bottomNavigationBar
.addItem(new BottomNavigationItem(R.drawable.ic_home_selected,"首页").setInactiveIcon(ContextCompat.getDrawable(this,R.drawable.ic_home_normal)))//非选中的图片)
.addItem(new BottomNavigationItem(R.drawable.ic_girl_selected,"美女").setInactiveIcon(ContextCompat.getDrawable(this,R.drawable.ic_girl_normal)))
.addItem(new BottomNavigationItem(R.drawable.ic_video_selected,"关注").setInactiveIcon(ContextCompat.getDrawable(this,R.drawable.ic_video_normal)))
.addItem(new BottomNavigationItem(R.drawable.ic_care_selected,"个人").setInactiveIcon(ContextCompat.getDrawable(this,R.drawable.ic_care_normal)))
.setFirstSelectedPosition(0)
.initialise();
bottomNavigationBar.hide();//隐藏
bottomNavigationBar.hide(true);//隐藏是否启动动画,这里并不能自定义动画
//bottomNavigationBar.setBarBackgroundColor(R.color.white);//背景颜色
// bottomNavigationBar.setInActiveColor("");//未选中时的颜色
// bottomNavigationBar.setActiveColor("#FD8822");//选中时的颜色
}
@Override
public void onTabSelected(int position){
FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
switch(position){
case 0:
if(blankFragment==null){
try{
blankFragment=Home_Fragment.class.newInstance();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
}
transaction.replace(R.id.fragment_container,blankFragment);
break;
case 1:
if(blankFragment2==null){
try{
blankFragment2=GirlFragment.class.newInstance();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
}
transaction.replace(R.id.fragment_container,blankFragment2);
break;
case 2:
if(blankFragment3==null){
try{
blankFragment3=VadioFragment.class.newInstance();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
}
transaction.replace(R.id.fragment_container,blankFragment3);
break;
case 3:
if(blankFragment4==null){
try{
blankFragment4=CareFragment.class.newInstance();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
}
transaction.replace(R.id.fragment_container,blankFragment4);
break;
default:
if(blankFragment==null){
try{
blankFragment=Home_Fragment.class.newInstance();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
}
transaction.replace(R.id.fragment_container,blankFragment);
break;
}
transaction.commit();
}
@Override
public void onTabUnselected(int position){
}
@Override
public void onTabReselected(int position){
}
//沉浸式状态栏的属性
private void initBar(){
// ImmersionBar.with(this)
// .statusBarColor(R.color.colorPrimary)
// .fitsSystemWindows(true) //使用该属性必须指定状态栏的颜色,不然状态栏透明,很难看
// .fullScreen(true) //有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏
// .hideBar(BarHide.FLAG_HIDE_BAR) //隐藏状态栏或导航栏或两者,不写默认不隐藏
//
// .keyboardEnable(true) //解决软键盘与底部输入框冲突问题
// // .keyboardEnable(true, WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
// // | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) //软键盘自动弹出
// .init();
//或者
// ImmersionBar.with(this)
// .transparentStatusBar() //透明状态栏,不写默认透明色
// .transparentNavigationBar() //透明导航栏,不写默认黑色(设置此方法,fullScreen()方法自动为true)
// .transparentBar() //透明状态栏和导航栏,不写默认状态栏为透明色,导航栏为黑色(设置此方法,fullScreen()方法自动为true)
// .statusBarColor(R.color.colorPrimary) //状态栏颜色,不写默认透明色
// .navigationBarColor(R.color.colorPrimary) //导航栏颜色,不写默认黑色
// .barColor(R.color.colorPrimary) //同时自定义状态栏和导航栏颜色,不写默认状态栏为透明色,导航栏为黑色
// .statusBarAlpha(0.3f) //状态栏透明度,不写默认0.0f
// .navigationBarAlpha(0.4f) //导航栏透明度,不写默认0.0F
// .barAlpha(0.3f) //状态栏和导航栏透明度,不写默认0.0f
// .statusBarDarkFont(true) //状态栏字体是深色,不写默认为亮色
.flymeOSStatusBarFontColor(R.color.btn3) //修改flyme OS状态栏字体颜色
// .fullScreen(true) //有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏
// .hideBar(BarHide.FLAG_HIDE_BAR) //隐藏状态栏或导航栏或两者,不写默认不隐藏
.addViewSupportTransformColor(toolbar) //设置支持view变色,可以添加多个view,不指定颜色,默认和状态栏同色,还有两个重载方法
// .titleBar(bottomNavigationBar) //解决状态栏和布局重叠问题,任选其一
// .titleBarMarginTop(bottomNavigationBar) //解决状态栏和布局重叠问题,任选其一
// .statusBarView(bottomNavigationBar) //解决状态栏和布局重叠问题,任选其一
// .fitsSystemWindows(true) //解决状态栏和布局重叠问题,任选其一,默认为false,当为true时一定要指定statusBarColor(),不然状态栏为透明色,还有一些重载方法
// .supportActionBar(true) //支持ActionBar使用
// .statusBarColorTransform(R.color.orange) //状态栏变色后的颜色
// .navigationBarColorTransform(R.color.orange) //导航栏变色后的颜色
// .barColorTransform(R.color.orange) //状态栏和导航栏变色后的颜色
.removeSupportView(bottomNavigationBar) //移除指定view支持
// .removeSupportAllView() //移除全部view支持
// .navigationBarEnable(true) //是否可以修改导航栏颜色,默认为true
// .navigationBarWithKitkatEnable(true) //是否可以修改安卓4.4和emui3.1手机导航栏颜色,默认为true
// .fixMarginAtBottom(true) //已过时,当xml里使用android:fitsSystemWindows="true"属性时,解决4.4和emui3.1手机底部有时会出现多余空白的问题,默认为false,非必须
// .addTag("tag") //给以上设置的参数打标记
// .getTag("tag") //根据tag获得沉浸式参数
// .reset() //重置所以沉浸式参数
// .keyboardEnable(true) //解决软键盘与底部输入框冲突问题,默认为false,还有一个重载方法,可以指定软键盘mode
// .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) //单独指定软键盘模式
// .setOnKeyboardListener(new OnKeyboardListener() { //软键盘监听回调
// @Override
// public void onKeyboardChange(boolean isPopup, int keyboardHeight) {
// Logger.e(isPopup + ""); //isPopup为true,软键盘弹出,为false,软键盘关闭
// }
// })
// .init(); //必须调用方可沉浸式
}
//第二种底部导航栏
第二种底部导航栏 :
implementation'com.hjm:BottomTabBar:1.1.3'
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottom_tab_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tab_bar_background="#FFFFFF"
app:tab_divider_background="#FF0000"
app:tab_divider_height="5dp"
app:tab_font_size="6sp"
app:tab_img_font_padding="0dp"
app:tab_img_height="30dp"
app:tab_img_width="30dp"
app:tab_isshow_divider="true"
app:tab_padding_bottom="5dp"
app:tab_padding_top="8dp"
app:tab_selected_color="#000000"
app:tab_unselected_color="@color/colorPrimary"/>
mBottomTabBar=(BottomTabBar)findViewById(R.id.bottom_tab_bar);
mBottomTabBar
.init(getSupportFragmentManager())
.setImgSize(70,70)//设置图片尺寸
.setFontSize(10)//设置文字大小
.setTabPadding(4,6,10)//设置ICON图片与上部分割线的间隔、图片与文字的间隔、文字与底部的间隔
.setChangeColor(Color.DKGRAY,Color.GREEN)//设置选中的颜色、未选中的颜色
.addTabItem("首页",R.drawable.aa,ShouyeFragment.class)
.addTabItem("发现",R.drawable.bb,FaxianFragment.class)
.addTabItem("最近",R.drawable.cc,ZuijinFragment.class)
.addTabItem("我的",R.drawable.dd,WodeFragment.class)
.isShowDivider(false)//设置是否显示分割线
.setTabBarBackgroundColor(Color.WHITE)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener(){
@Override
public void onTabChange(int position,String name,View view){
}
}).setCurrentTab(0);//设置当前选中的Tab,从0开始
第三种 底部 导航栏
implementation'com.jpeng:JPTabBar:1.2.3'
// 如果想在中间设置图片突起的话,父布局必须得是相对布局和,帧布局,它的高度得定死
第三种 底部 导航栏:
mTabbar.setTitles(R.string.tab1, R.string.tab2, R.string.tab3, R.string.tab4)
.setNormalIcons(R.mipmap.tab1_normal, R.mipmap.tab2_normal, R.mipmap.tab3_normal, R.mipmap.tab4_normal)
.setSelectedIcons(R.mipmap.tab1_selected, R.mipmap.tab2_selected, R.mipmap.tab3_selected, R.mipmap.tab4_selected)
.generate();
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="db.lanxing.t1.view.homeactivity.MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/tabBar" />
<com.jpeng.jptabbar.JPTabBar
android:id="@+id/tabBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:TabIconSize="20dp"
app:TabMiddleView="@layout/item"
/>
</RelativeLayout>
java代码,利用反射注解
@Titles
private static final String[]mTitles={"页面一","页面二","页面三","页面四"};
@SeleIcons
private static final int[]mSeleIcons={R.mipmap.a,R.mipmap.b,R.mipmap.c,R.mipmap.d};
@NorIcons
private static final int[]mNormalIcons={R.mipmap.aa,R.mipmap.bb,R.mipmap.cc,R.mipmap.dd};
//获取中间图片的id
View middleView=tabBar.getMiddleView();
ImageView imageView=middleView.findViewById(R.id.img);
//关联viewPager
tabBar.setContainer(viewPager);
package db.lanxing.mydb.view.fragment.shujuChild;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import db.lanxing.mydb.R;
import db.lanxing.mydb.contract.MyContract;
import db.lanxing.mydb.module.MyModel;
import db.lanxing.mydb.module.adapter.MyRecyAdapter;
import db.lanxing.mydb.module.data.App;
import db.lanxing.mydb.module.data.EventBusMessage;
import db.lanxing.mydb.module.data.beans.Girl_Bean;
import db.lanxing.mydb.module.data.beans.TouTiaoBean;
import db.lanxing.mydb.module.data.beans.Video_Bean;
import db.lanxing.mydb.preseter.MyPresenter;
import db.lanxing.mydb.view.activity.XiangQingActivity;
import db.lanxing.mydb.view.fragment.BaseFragment;
/**
* A simple {@link Fragment} subclass.
*/
public class ShuJuFragment extends BaseFragment<MyModel, MyPresenter> implements MyContract.View {
@BindView(R.id.recy)
RecyclerView recy;
@BindView(R.id.sma)
SmartRefreshLayout sma;
@BindView(R.id.ll)
LinearLayout ll;
@BindView(R.id.ftab)
FloatingActionButton ftab;
Unbinder unbinder;
private MyRecyAdapter recyAdapter;
private ValueAnimator valueAnimator;
private View viewById;
public ShuJuFragment() {
}
private List<TouTiaoBean.T1348647909107Bean> lists = new ArrayList<>();
private String mParam1;
private String mParam2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(App.ARG_PARAM1);
mParam2 = getArguments().getString(App.ARG_PARAM2);
}
}
@Override
protected int getLayoutId() {
return R.layout.fragment_blank_fragment3;
}
@Override
protected void initView(View view) {
unbinder = ButterKnife.bind(this, view);
viewById = getActivity().findViewById(R.id.bottom_navigation_bar);
initBar();
recy.setLayoutManager(new LinearLayoutManager(getContext()));
p.getPUrl(mParam1, mParam2, "0", "20");
Toast.makeText(getContext(), mParam1 + mParam2, Toast.LENGTH_SHORT).show();
recyAdapter = new MyRecyAdapter(R.layout.item, lists);
recyAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);//加载动画
recyAdapter.isFirstOnly(false);//执行次数是否只一次
recy.setAdapter(recyAdapter);
startAnimation();
}
private void initBar() {
// mImmersionBar.keyboardEnable(true).navigationBarColor(R.color.colorPrimary).navigationBarWithKitkatEnable(false).init();
}
private void initRefreshData() {
sma.setRefreshHeader(new ClassicsHeader(getContext()));
// 设置 Footer 为 球脉冲 样式
sma.setRefreshFooter(new BallPulseFooter(getContext()).setSpinnerStyle(SpinnerStyle.Scale));
sma.setRefreshFooter(new ClassicsFooter(getContext()).setSpinnerStyle(SpinnerStyle.Scale));
sma.setReboundDuration(100);
sma.setScrollBarFadeDuration(100);
sma.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
// handler.postDelayed(runnable, 10);
p.getPUrl(mParam1, mParam2, "0", "20");
refreshlayout.finishRefresh(1000/*,false*/);
}
}); // 传入false表示刷新失败
sma.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(RefreshLayout refreshlayout) {
p.getPUrl(mParam1, mParam2, "0", "30");
// handler.postDelayed(runnable, 10);
// Toast.makeText(MainActivity.this, "加载完成", Toast.LENGTH_SHORT).show();
refreshlayout.finishLoadMore(1000/*,false*/);
// 传入false表示加载失败
}
});
}
private void initTouch() {
recyAdapter.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
Intent intent = new Intent(getActivity(), XiangQingActivity.class);
EventBusMessage eventBusMessage = new EventBusMessage(lists.get(position).getImgsrc(), lists.get(position).getTitle(), lists.get(position).getUrl());
EventBus.getDefault().postSticky(eventBusMessage);
startActivity(intent);
return true;
}
});
recyAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
Intent intent = new Intent(getActivity(), XiangQingActivity.class);
EventBusMessage eventBusMessage = new EventBusMessage(lists.get(position).getImgsrc(), lists.get(position).getTitle(), lists.get(position).getUrl());
EventBus.getDefault().postSticky(eventBusMessage);
startActivity(intent);
}
});
recy.setOnScrollListener(new RecyclerView.OnScrollListener() {
//RecyclerView 滑动 事件 -1 表示 向上, 1 表示向下。
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (!recyclerView.canScrollVertically(-1)) {
} else if (!recyclerView.canScrollVertically(1)) {
} else if (dy < 0) {
onScrolledUp();
} else if (dy > 0) {
onScrolledDown();
}
super.onScrolled(recyclerView, dx, dy);
}
public void onScrolledUp() {
View linearLayout = getActivity().findViewById(R.id.bottom_navigation_bar);
linearLayout.setVisibility(View.VISIBLE);
ftab.setVisibility(View.GONE);
}
public void onScrolledDown() {
View view = getActivity().findViewById(R.id.bottom_navigation_bar);
view.setVisibility(View.GONE);
ftab.setVisibility(View.VISIBLE);
}
});
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
boolean a = true;
private void startAnimation() {
recy.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (a) {
ftab.setVisibility(View.VISIBLE);
} else {
ftab.setVisibility(View.GONE);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy < -1) {
a = true;
} else if (dy > 1) {
a = false;
}
}
});
}
@Override
public void getVTouTiaoData(final List<TouTiaoBean.T1348647909107Bean> list) {
// Toast.makeText(getContext(), "list:" + list, Toast.LENGTH_SHORT).show();
lists.addAll(list);
recyAdapter.notifyDataSetChanged();
ll.setVisibility(View.GONE);
initTouch();
initRefreshData();
}
@Override
public void getVData_Video(List<Video_Bean.V9LG4E6VRBean> list) {
}
@Override
public void getVGirlData(List<Girl_Bean.ResultsBean> list) {
}
@Override
public void Error(String message) {
Log.d("ShuJuFragment", message);
}
@OnClick(R.id.ftab)
public void onViewClicked() {
recy.smoothScrollToPosition(0);
}
}
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。