在Sherlock ActionBar选项卡视图中将标题文本大小写更改为小写

时间:2014-03-12 09:24:40

标签: android actionbarsherlock

我使用Sherlock ActionBar Tab Views创建了一个标签应用程序。我喜欢将Tab标题更改为小写。看屏幕截图

enter image description here

我想将TAB1更改为tab1

非常感谢任何解决方案

我的代码如下

public class MainActivity extends SherlockFragmentActivity {

// Declare Variables
ActionBar mActionBar;
ViewPager mPager;
Tab tab;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from activity_main.xml
    setContentView(R.layout.activity_main);

    // Activate Navigation Mode Tabs
    mActionBar = getSupportActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Locate ViewPager in activity_main.xml
    mPager = (ViewPager) findViewById(R.id.pager);

    // Activate Fragment Manager
    FragmentManager fm = getSupportFragmentManager();

    // Capture ViewPager page swipes
    ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            // Find the ViewPager Position
            mActionBar.setSelectedNavigationItem(position);
        }
    };

    mPager.setOnPageChangeListener(ViewPagerListener);
    // Locate the adapter class called ViewPagerAdapter.java
    ViewPagerAdapter viewpageradapter = new ViewPagerAdapter(fm);
    // Set the View Pager Adapter into ViewPager
    mPager.setAdapter(viewpageradapter);

    // Capture tab button clicks
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // Pass the position on tab click to ViewPager
            mPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }
    };

    // Create first Tab
    tab = mActionBar.newTab().setText("Tab1").setTabListener(tabListener);
    mActionBar.addTab(tab);

    // Create second Tab
    tab = mActionBar.newTab().setText("Tab2").setTabListener(tabListener);
    mActionBar.addTab(tab);

    // Create third Tab
    tab = mActionBar.newTab().setText("Tab3").setTabListener(tabListener);
    mActionBar.addTab(tab);

 }

感谢

4 个答案:

答案 0 :(得分:5)

在styles.xml中为您的Tablayout添加样式

<style name="TabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
</style>

然后将该属性添加为:

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        app:tabTextAppearance="@style/TabTextAppearance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

我测试了它。它会工作。

答案 1 :(得分:1)

Please add this in TabLayout tag of xml file

app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

this will help you :)

答案 2 :(得分:0)

试试这个鳕鱼

text-transform: capitalize;

答案 3 :(得分:0)

试试这个: -

   tab = mActionBar.newTab().setText("Tab1").setTabListener(tabListener);
    mActionBar.addTab(tab);

    TextView x1 = (TextView) mTabHost.getTabWidget().getChildAt(0)
              .findViewById(android.R.id.title);
      x1.setAllCaps(false); 

      // Create second Tab
    tab = mActionBar.newTab().setText("Tab2").setTabListener(tabListener);
    mActionBar.addTab(tab);
       TextView x2 = (TextView) mTabHost.getTabWidget().getChildAt(0)
              .findViewById(android.R.id.title);
      x2.setAllCaps(false); 
    // Create third Tab
    tab = mActionBar.newTab().setText("Tab3").setTabListener(tabListener);
    mActionBar.addTab(tab);
 TextView x3 = (TextView) mTabHost.getTabWidget().getChildAt(0)
              .findViewById(android.R.id.title);
      x3.setAllCaps(false);