您的位置:首页 > 其它

//BottomTabBar实现底部选项卡

2017-10-26 10:30 274 查看
//依赖

compile 'com.hjm:BottomTabBar:1.1.1'

//布局文件

<com.hjm.bottomtabbar.BottomTabBar

        android:id="@+id/btb"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        >

    </com.hjm.bottomtabbar.BottomTabBar>

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);

                            }

                        }

                    }

                });

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: