package com.example.shazidouhuiapp.activity;
import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.example.shazidouhuiapp.Adapter.setAdapter;
import com.example.shazidouhuiapp.R;
import com.example.shazidouhuiapp.fragment.FragmentMine;
import com.example.shazidouhuiapp.fragment.FragmentReadOver;
import com.example.shazidouhuiapp.fragment.FragmentUnfinished;
import java.util.ArrayList;
import java.util.List;
public
class
studentinterface extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener, ViewPager.OnPageChangeListener {
private
ViewPager viewPager;
private
BottomNavigationBar bottomNavigationBar;
private
List<Fragment> fragmentList;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager=findViewById(R.id.viewpager);
bottomNavigationBar=findViewById(R.id.bottom);
initView();
}
private
void
initView() {
initViewPager();
initBottom();
}
private
void
initBottom() {
bottomNavigationBar.setTabSelectedListener(
this
);
bottomNavigationBar.clearAll();
bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_DEFAULT);
bottomNavigationBar.setBarBackgroundColor(R.color.white).setActiveColor(R.color.colorbasel)
.setInActiveColor(R.color.black);
bottomNavigationBar.addItem(
new
BottomNavigationItem(R.drawable.homepage_fill,
"未完成作业"
).setInactiveIconResource(R.drawable.homepage))
.addItem(
new
BottomNavigationItem(R.drawable.mobilephone_fill,
"已批改作业"
).setInactiveIconResource(R.drawable.mobilephone))
.addItem(
new
BottomNavigationItem(R.drawable.mine_fill,
"我的"
).setInactiveIconResource(R.drawable.mine))
.setFirstSelectedPosition(0)
.initialise();
}
private
void
initViewPager() {
viewPager.setOffscreenPageLimit(3);
//配置fragment
fragmentList=
new
ArrayList<>();
//三个底部导航栏的实例化
fragmentList.add(
new
FragmentUnfinished());
fragmentList.add(
new
FragmentReadOver());
fragmentList.add(
new
FragmentMine());
viewPager.setAdapter(
new
setAdapter(getSupportFragmentManager(),fragmentList));
viewPager.addOnPageChangeListener(
this
);
viewPager.setCurrentItem(0);
}
@Override
public
void
onTabSelected(
int
position) {
}
@Override
public
void
onTabUnselected(
int
position) {
}
@Override
public
void
onTabReselected(
int
position) {
viewPager.setCurrentItem(position);
}
@Override
public
void
onPageScrolled(
int
position,
float
positionOffset,
int
positionOffsetPixels) {
}
@Override
public
void
onPageSelected(
int
position) {
bottomNavigationBar.selectTab(position);
}
@Override
public
void
onPageScrollStateChanged(
int
state) {
}
}