0
我想在選項卡中實現fontawesome。這是重要的事情。FontAwesome實現TabLayout中的選項卡
MainActivity中的OnCreate:
private void setupViewPager(ViewPager viewPager) {
AdapterViewPager adapter = new AdapterViewPager(getSupportFragmentManager());
//Kreiraš fragment, ki bo v ViewPagerju
adapter.addFragment(new Fragment1(), "HOME");
adapter.addFragment(new Fragment2(), "HEART");
adapter.addFragment(new Fragment3(), "CRITERIA");
viewPager.setAdapter(adapter);
viewPager.setOffscreenPageLimit(2);
}
定製AdapterViewPager:
public class AdapterViewPager extends FragmentStatePagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public AdapterViewPager(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
如何才能做到這一點
viewPager = (ViewPager) findViewById(R.id.pager);
setupViewPager(viewPager); //Kreiramo viewpager oz. klic funkcije
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
if (tabLayout != null) {
tabLayout.setupWithViewPager(viewPager); //Poveže tab_layout z viewpagerjem
}
是在MainActivity爲viewpager的方法?有任何想法嗎?
感謝您的幫助,但現在它看起來像這樣:http://prntscr.com/cc7xij任何方式來增加它的大小和改變顏色,就像它是指標? – WinterChilly
當然有可能,有很多關於增加tabLayout中的字體大小或TabLayout選擇器 – Amir
如果你沒有找到任何東西讓我來幫你:) – Amir