I'm developing a screen with three fragments tabs. The tabs title only have their first letter in uppercase:
private String[] tabs = { "About Me", "Education","ProfileEdit"};
But when I run the app, the titles are displayed all in uppercase.
How can I make the tabs display the words properly?
Tabs setup code:
private String[] tabs = { "About Me", "Education","ProfileEdit"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editprofile);
user=(UserModel)getIntent().getSerializableExtra("USER");
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name.toLowerCase())
.setTabListener(this));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
UPDATE
I edited the theme with textAllCaps false, but the words display the same way:
<resources>
<style name="MyTheme" parent="Theme.Sherlock">
<item name="actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
Add styles for your Tablayout in styles.xml
<style name="TabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
</style>
then add that attribute as:
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabTextAppearance="@style/TabTextAppearance"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I tested it. It'll work.
The default theme for tab views in Android 4.0 (the Holo theme) has android:textAllCaps set to true. See:
http://android-developers.blogspot.in/2011/04/customizing-action-bar.html
Use below code:
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="2dp"
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/white" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With