选项卡主机标题文本以大写形式显示需要以小写形式显示

tab host title text appears in upper case want in lowercase

我使用了 this 库,它的标题文本显示为大写 我已经引用

但没有得到正确的输出。

 <style name="AppTheme" parent="@style/Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:textColorPrimary">@color/text_color</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:actionBarTabTextStyle">@style/tab</item>
    <item name="actionBarTabTextStyle">@style/tab</item>

    <item name="android:windowBackground">@color/window_background</item>
    <item name="colorControlNormal">@color/accent</item>
    <item name="colorControlActivated">@color/secondary_text</item>
    <item name="colorControlHighlight">@color/secondary_text</item>
    <item name="android:homeAsUpIndicator">@drawable/ic_menu</item>

</style>

<style name="tab" parent="@style/Widget.AppCompat.Light.ActionBar.TabText">
    <item name="android:textAllCaps">false</item>
</style>

fragment.java:

    tabHost = (MaterialTabHost) v.findViewById(R.id.tabHost);
    adapter = new TabsPagerAdapter(getChildFragmentManager(), entity);
    pager = (ViewPager) v.findViewById(R.id.pager_entitiy_detail);
    pager.setOffscreenPageLimit(adapter.getCount());
    pager.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            tabHost.setSelectedNavigationItem(position);
            Log.e("DashDetail", "");
        }
    });

    // insert all tabs from pagerAdapter data
    for (int i = 0; i < adapter.getCount(); i++) {
        tabHost.addTab(
                tabHost.newTab()
                        .setText(adapter.getPageTitle(i))
                        .setTabListener(this)
        );

    }

在选项卡主机和适配器设置文本中使用了上面的代码,但没有得到小写文本。

在您的 for loop 中尝试添加 tabs

试试这个

TextView tv =  (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); 
tv.setAllCaps(false);

像这样:--

    for (int i = 0; i < adapter.getCount(); i++) {
                tabHost.addTab(
                                 tabHost.newTab()
                                .setText(adapter.getPageTitle(i))
                                .setTabListener(this)
TextView tv =  (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); 
tv.setAllCaps(false);
                );

或者你可以在你的 PagerAdapter

中像下面那样做
@Override
        public CharSequence getPageTitle(int position) {
            Locale l = Locale.getDefault();
            switch (position) {
                case 0:
                    return "ONE".toLowerCase();
}
return null;
}

希望对您有所帮助。

谢谢,我已经完成了上面所示的答案中的建议,但仍然没有用,所以我通过检查代码并分析它对库进行了更改。我发现提到了 .toUpperCase() 并且我从那里删除并且它有效。