user3454856
user3454856

Reputation: 17

How to increase the android action bar tabs text size

I used TabsPagerAdapter and ViewPager to implement tabs in my action bar. I did it but my problem is tabs text is showing small size in tablets(tvdpi device). Can u please tell me how to increase tabs text size.

Thank you.

ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    ActionBar actionBar = getSupportActionBar();
    TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager(),
            getIntent().getBundleExtra("rechargeInfo"));

    viewPager.setAdapter(mAdapter);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

     //Adding Tabs
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name)
                .setTabListener(this));
    }

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onTabSelected(Tab tab, FragmentTransaction arg1) {
    // TODO Auto-generated method stub
    viewPager.setCurrentItem(tab.getPosition());

}

@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}



import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.amulyam.users.BalanceFragment;
import com.amulyam.users.RechargeActivity;
import com.amulyam.users.SpecialOffersFragment;

public class TabsPagerAdapter extends FragmentStatePagerAdapter {
    private Bundle rechargeInfo;

    public TabsPagerAdapter(FragmentManager fm, Bundle rechargeInfo) {
        super(fm);
        this.rechargeInfo = rechargeInfo;
    }

    @Override
    public Fragment getItem(int index) {

        switch (index) {
        case 0:
            // Special Offers fragment activity
            return new SpecialOffersFragment();
        case 1:
            // Balance fragment activity
            return new BalanceFragment();
        case 2:
            // Recharge fragment activity

            RechargeActivity rechargeActivity = new RechargeActivity();
            rechargeActivity.setArguments(rechargeInfo);

            return rechargeActivity;
        }

        return null;
    }

    @Override
    public int getCount() {
        // get item count - equal to number of tabs
        return 3;
    }

}

Upvotes: 0

Views: 891

Answers (2)

Avner Gidron
Avner Gidron

Reputation: 411

I think you ment you are using swipe tabs. if that is what you ment then you can go to the pager layout and inside the android.support.v4.view.PagerTitleStrip write android:textSize="xxsp" where xx is the size you want. for example I did it like so:

    <android.support.v4.view.ViewPager

  xmlns:android="http://schemas.android.com/apk/res/android"  
  android:layout_width="match_parent"
  android:id="@+id/pager"
  android:layout_height="match_parent">


  <android.support.v4.view.PagerTitleStrip
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/title"
      android:layout_gravity="top"
      android:textSize="25sp"
      >
  </android.support.v4.view.PagerTitleStrip>

 </android.support.v4.view.ViewPager>

and you can do the same for the color and backgrounds: android:textColor="@color/black"

Hope this will help you

Upvotes: 0

Giridharan
Giridharan

Reputation: 4462

try this.. it would help you

TextView x = (TextView) tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title);
x.setTextSize(25);

Upvotes: 1

Related Questions