我想將圖標添加到Android中的TabLayout中的我的選項卡中。 我試過圖標數組和getTitle方法。我沒有得到任何圖標。 選項卡僅保留標題文本,標題文本數組中的文本完全不用。 這裏是我的代碼:將圖標添加到Android中的TabLayout中的選項卡中
import statements...
public class scatter extends FragmentActivity {
some variable declarations...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scatter);
sensorUID = getIntent().getStringExtra("sUID");
tankname = getIntent().getStringExtra("tNAME");
SCALE_C = (getIntent().getStringExtra("tSCALEC"));
SCALE_M = (getIntent().getStringExtra("tSCALEM"));
DPs = (getIntent().getStringExtra("tDP"));
UNITs = (getIntent().getStringExtra("tUNIT"));
numVar = Integer.parseInt(DPs);
final ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Graph"));
tabLayout.addTab(tabLayout.newTab().setText("Values"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
pager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int pos) {
Fragment fragment;
Bundle args = new Bundle();
args.putString("senID", sensorUID);
args.putInt("numVar", numVar);
switch (pos) {
case 0:
fragment = FirstFragment.newInstance("FirstFragment, Instance 1");
break;
case 1:
fragment = SecondFragment.newInstance("SecondFragment, Instance 1");
break;
default:
fragment = FirstFragment.newInstance("FirstFragment, Instance 1");
break;
}
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
return 2;
}
}
}
要改變,你必須創建自定義選項卡:在機器人CustomTabs(http://stackoverflow.com/questions/3903796/ Android的定製標籤) – activesince93