【问题标题】:how i can add icon to page title android java我如何将图标添加到页面标题android java
【发布时间】:2016-03-20 20:07:34
【问题描述】:

如何在页面标题中添加图标?我曾尝试添加一个 drwable,但是当我使用应用程序时,没有图标,而是图标位置的文本

   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;
    }
}

【问题讨论】:

    标签: java android


    【解决方案1】:

    getPageTitle() 允许您仅配置文本,而不是图标。可以看到函数的返回类型是CharSequence。如果要设置图标,则需要手动进行。检查这个问题:Tab icon and text both using android design support library

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      相关资源
      最近更新 更多