android adapter 标题,如何在android FragmentPagerAdapter中添加页面标题和图标

我必须在标题页标题中显示带有相应图标的标题.喜欢这个图像.但只能显示标题而不是图标.

这是我所做的代码.

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 DummySectionFragment (defined as a static inner class

// below) with the page number as its lone argument.

Log.e("POSITION", "position=" + position);

Fragment fragment;

switch (position) {

case 0:

//Fragment1

case 1:

//Fragment2

case 2:

//Fragment3

case 3:

//Fragment4

case 4:

//Fragment5

}

return null;

}

@Override

public int getCount() {

return NUM_PAGES;

}

// using both these techniques but could not get icon in title

/*

* public int getIconResId(int index) { return ICONS[index % ICONS.length]; }

*/

public int getPageIconResId(int position) {

return ICONS[position];

}

@Override

public CharSequence getPageTitle(int position) {

Locale l = Locale.getDefault();

switch (position) {

case 0:

return getString(R.string.title_section1).toUpperCase(l);

case 1:

return getString(R.string.title_section2).toUpperCase(l);

case 2:

return getString(R.string.title_section3).toUpperCase(l);

case 3:

return getString(R.string.title_section4).toUpperCase(l);

case 4:

return getString(R.string.title_section5).toUpperCase(l);

}

return null;

}

}

并在onCreate:

mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.

mViewPager = (ViewPager) findViewById(R.id.pager);

mViewPager.setAdapter(mSectionsPagerAdapter);

使用此xml文件在片段中显示片段页面适配器;

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/pager"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/rlv2"

android:layout_marginTop="-30dp" >

android:id="@+id/pager_title_strip"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:paddingBottom="4dp"

android:paddingTop="4dp"

android:textColor="@color/black"

android:textStyle="bold" />

在这张照片中,最终我希望成为.但只在我的应用程序中显示没有图标.你能不知道如何显示带有图标和标题的节页面适配器.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值