//BottomTabBar實現底部選項卡
阿新 • • 發佈:2019-01-26
public class MyActivty_Main extends AppCompatActivity {
private BottomTabBar bottomTabBar;
private List<Fragment> list;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activty__main);
bottomTabBar= (BottomTabBar) findViewById(R.id.btb);
list=new ArrayList<>();
list.add(new Fragment_a());
list.add(new Fragment_b());
list.add(new Fragment_c());
bottomTabBar.init(getSupportFragmentManager())
.setImgSize(90, 90)
.setFontSize(1)
.setTabPadding(4, 6, 10)
.setChangeColor(Color.GREEN, Color.RED)
.addTabItem(" ", R.mipmap.index_checked, R.mipmap.index_unchecked, Fragment_a.class)
.addTabItem(" ", R.mipmap.recommand_checked, R.mipmap.recommand_unchecked, Fragment_b.class)
.addTabItem(" ", R.mipmap.mine_checked, R.mipmap.mine_unchecked,Fragment_c.class)
.isShowDivider(false)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
@Override
public void onTabChange(int position, String name) {
Log.i("TGA", "位置:" + position + " 選項卡:" + name);
sp = MyUtil.getSharedPreferencesInstance(MyActivty_Main.this);
if (position==2){
boolean auto = sp.getBoolean("check", false);
if (auto==false){
Intent intent=new Intent(MyActivty_Main.this,MainActivity_Login.class);
startActivity(intent);
}
}
}
});
}
}
private BottomTabBar bottomTabBar;
private List<Fragment> list;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activty__main);
bottomTabBar= (BottomTabBar) findViewById(R.id.btb);
list=new ArrayList<>();
list.add(new Fragment_a());
list.add(new Fragment_b());
list.add(new Fragment_c());
bottomTabBar.init(getSupportFragmentManager())
.setImgSize(90, 90)
.setFontSize(1)
.setTabPadding(4, 6, 10)
.setChangeColor(Color.GREEN, Color.RED)
.addTabItem(" ", R.mipmap.index_checked, R.mipmap.index_unchecked, Fragment_a.class)
.addTabItem(" ", R.mipmap.recommand_checked, R.mipmap.recommand_unchecked, Fragment_b.class)
.addTabItem(" ", R.mipmap.mine_checked, R.mipmap.mine_unchecked,Fragment_c.class)
.isShowDivider(false)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
@Override
public void onTabChange(int position, String name) {
Log.i("TGA", "位置:" + position + " 選項卡:" + name);
sp = MyUtil.getSharedPreferencesInstance(MyActivty_Main.this);
if (position==2){
boolean auto = sp.getBoolean("check", false);
if (auto==false){
Intent intent=new Intent(MyActivty_Main.this,MainActivity_Login.class);
startActivity(intent);
}
}
}
});
}
}