我在tablayout中发现了一个问题,TableLayout的标题总是以大写字母显示,如何解决这个问题?
我从strings.xml获取标题文本,适配器如下:
static class Adapter extends FragmentPagerAdapter {
private final List<Fragment> mFragments = new ArrayList<>();
private final List<String> mFragmentTitles = new ArrayList<>();
Adapter(FragmentManager fm) {
super(fm);
}
void addFragment(Fragment fragment, String title) {
mFragments.add(fragment);
mFragmentTitles.add(title);
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitles.get(position);
}
}
public static Fragment create() {
return new SearchFragment();
}
}
的strings.xml
<string name="Repositories">Repositories</string>
<string name="Code">Code</string>
<string name="Issues">Issues</string>
<string name="Users">Users</string>
答案 0 :(得分:0)
用此
替换您的代码它会起作用
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
static class Adapter extends FragmentPagerAdapter {
private final List<Fragment> mFragments = new ArrayList<>();
private final List<String> mFragmentTitles = new ArrayList<>();
Adapter(FragmentManager fm) {
super(fm);
}
void addFragment(Fragment fragment, String title) {
mFragments.add(fragment);
mFragmentTitles.add(title);
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitles.get(position).toLowerCase();
}
}
public static Fragment create() {
return new SearchFragment();
}
}