我如何在页面标题中添加图标?我试图添加一个drwable,但是当我使用app时,没有图标,但是文本到图标的位置
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
// Show 2 total pages.
return 2;
}
Drawable myDrawable;
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
myDrawable = getResources().getDrawable(R.drawable.abc_btn_rating_star_off_mtrl_alpha);
return ("Messaggi "+myDrawable);
case 1:
return "File ";
}
return null;
}
}
答案 0 :(得分:0)
getPageTitle()
允许您仅配置文本,而不是图标。您可以看到该函数的返回类型为CharSequence
。如果要设置图标,则需要手动执行。请检查此问题:Tab icon and text both using android design support library