最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Pagerslidingtabstrip菜单标题栏制作方法
时间:2022-06-25 23:16:05 编辑:袖梨 来源:一聚教程网
本文实例为大家分享了Pagerslidingtabstrip菜单标题栏的具体代码,供大家参考,具体内容如下
1.加入library作为本地包工程,或者加入依赖在build.gradle(我对gradle不是很了解,所以用前面那个导入包的方法)
dependencies { compile 'com.astuetz:pagerslidingtabstrip:1.0.1' }
2、布局文件
3、MainActivity代码 有多少个标题就写多少个Fragment
public class MainActivity extends AppCompatActivity { private PagerSlidingTabStrip pst; private ViewPager vp; private Listadlist; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pst = (PagerSlidingTabStrip) findViewById(R.id.tabs); vp = (ViewPager) findViewById(R.id.vp); new Thread(){ private String json; @Override public void run() { super.run(); String path="http://www.meirixue.com/api.php?c=index&a=index"; json = NetWork.getJson(path); runOnUiThread(new Runnable() { @Override public void run() { Gson gson = new Gson(); Bean bean = gson.fromJson(json, Bean.class); adlist = bean.getData().getAdlist(); vp.setAdapter(new MyPagerAdapter(getSupportFragmentManager())); pst.setViewPager(vp); } }); } }.start(); } //适配器 class MyPagerAdapter extends FragmentPagerAdapter{ public MyPagerAdapter(FragmentManager supportFragmentManager) { super(supportFragmentManager); } @Override public CharSequence getPageTitle(int position) { String name = adlist.get(position).getName(); return name; } @Override public Fragment getItem(int position) { Fragment fragment=null; switch (position){ case 0: fragment = new Fragment1(); break; case 1: fragment = new Fragment2(); break; case 2: fragment = new Fragment3(); break; case 3: fragment = new Fragment4(); break; } return fragment; } @Override public int getCount() { return adlist.size(); } } }
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22