美文网首页高级UI实用
Android底部栏,简单最实用方便

Android底部栏,简单最实用方便

作者: 总会颠沛流离 | 来源:发表于2019-06-23 16:23 被阅读6次
image
githup地址(https://github.com/gyadministrator/GYBottomBar

第一步

1:

allprojects {

repositories {

        maven {

            url 'https://jitpack.io'

        }

}

}

2:

 dependencies {
    implementation 'com.github.gyadministrator:GYBottomBar:1.1'
  }

第二步 然后在Activity里面使用就可以了

public class MainActivityextends AppCompatActivityimplements GYBottomBarView.IGYBottomBarChangeListener {
private GYBottomBarViewbottomView;  
private ListbarItems =new ArrayList<>();
Listfragments =new ArrayList<>();  
Listicons =new ArrayList<>();
@Override   
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);      
setContentView(R.layout.activity_main);        
bottomView = findViewById(R.id.bottomView);    
 initBarItems();        
 bottomView.setBarItems(barItems);        
 bottomView.setPositionBadge(0, 6);       
 bottomView.setPositionBadge(1, 0);       
 bottomView.setPositionBadge(2, 100);       
 initFragment();       
 initIcons();        b
 ottomView.setSelectIcon(icons);        
 bottomView.setFragments(getSupportFragmentManager(), fragments, R.id.fl_container);        
 bottomView.setBarChangeListener(this);   
 }


 private void initIcons() {
  icons.add(R.drawable.more);        
 icons.add(R.drawable.more);       
 icons.add(R.drawable.more);        
 icons.add(R.drawable.more);  
}

private void initFragment() {
fragments.add(TestFragment.newInstance());        
fragments.add(TestFragment1.newInstance());        
fragments.add(TestFragment2.newInstance());        
fragments.add(TestFragment3.newInstance());    
 }

 private void initBarItems() {
barItems.add(new GYBarItem("首页", R.mipmap.ic_launcher));        
barItems.add(new GYBarItem("视频", R.mipmap.ic_launcher));        
barItems.add(new GYBarItem("资讯", R.mipmap.ic_launcher));        
barItems.add(new GYBarItem("我的", R.mipmap.ic_launcher));  
}
 @Override

public void onSelected(int position) {
Toast.makeText(this, "点击了" + position, Toast.LENGTH_SHORT).show();

  }

 }

相关文章

网友评论

    本文标题:Android底部栏,简单最实用方便

    本文链接:https://www.haomeiwen.com/subject/hyadqctx.html