2016-06-28 2 views
1

나는 PodCastTab을 가지고있다 ... 나는 완전히 TabName을 표시하고 싶다 ??? 오전 TabHost에 대해 문의 하시겠습니까 ??TabLayout에서 탭 텍스트 크기를 늘리는 방법?

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    //Initializing the tablayout 
    tabLayout = (TabLayout) findViewById(R.id.tabLayout); 
    //Adding the tabs using addTab() method 
    tabLayout.addTab(tabLayout.newTab().setText("Home").setIcon(R.drawable.home_selector)); 

    tabLayout.addTab(tabLayout.newTab().setText("News").setIcon(R.drawable.news_selector)); 
    tabLayout.addTab(tabLayout.newTab().setText("Videos").setIcon(R.drawable.video_selector)); 
    tabLayout.addTab(tabLayout.newTab().setText("PodCasts").setIcon(R.drawable.podcast_selector)); 
    tabLayout.addTab(tabLayout.newTab().setText("More").setIcon(R.drawable.more_selector)); 
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); 
    //tabLayout.setupWithViewPager(viewPager); 

    //Initializing viewPager 
    viewPager = (ViewPager) findViewById(R.id.pager); 

    //Creating our pager adapter 
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount()); 

    //Adding adapter to pager 
    viewPager.setAdapter(adapter); 

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); 

    tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager) { 
     @Override 
     public void onTabSelected(TabLayout.Tab tab) { 

      if (tab.getPosition() == 0) { 
       bottombar.show(); 
      } else if (tab.getPosition() == 1) { 
       bottombar.hide(); 
      } else if (tab.getPosition() == 2) { 
       bottombar.hide(); 
      } else if (tab.getPosition() == 3) { 
       bottombar.hide(); 
      } 
      super.onTabSelected(tab); 
     } 

     @Override 
     public void onTabUnselected(TabLayout.Tab tab) { 
      super.onTabUnselected(tab); 

     } 
    }); 
} 

이는 XML을 파일

<LinearLayout 
android:id="@+id/main_layout" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".Activity.MainActivity"> 


<!-- our tablayout to display tabs --> 

<android.support.design.widget.TabLayout 
    android:id="@+id/tabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:tabBackground="@drawable/shape" 
    android:textAlignment="center" 
    app:tabTextColor="#838587" 
    app:tabSelectedTextColor="#fafafa" 
    app:tabIndicatorColor="#fffeff" 
    app:tabIndicatorHeight="2dp" 
    app:tabMode="fixed" 
    app:tabTextAppearance="@style/MyTabLayoutTextAppearance" 
    android:fitsSystemWindows="true" 
    app:tabMaxWidth="250dp" 
    android:minWidth="150sp" 
    app:tabGravity="fill"> 
</android.support.design.widget.TabLayout> 
<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"/> 

enter image description here 방법 : TabHost 및 TabLayout이이

한 번이 내 코드를 볼 탭

의 스크린 샷입니다 ... 다른 전체 탭 텍스트를 표시 하시겠습니까 ??

+0

가능한 복제를 호출하여 새로운 하나 (http://stackoverflow.com/questions/19442084/change-the-text-size-in-tab-in [안드로이드 탭에서 텍스트 크기를 변경] - 안드로이드) – Ironman

답변

0

당신은

RelativeLayout tab = (RelativeLayout) LayoutInflater 
       .from(MainActivity.this) 
       .inflate(R.layout.tab_layout, null, false); 

를 사용하여, 존재하지 않는 경우에 당신이 당신의 탭을 팽창 TabLayout

첫째 통해이 작업을 수행 할 수 있습니다 그리고 당신은 새 탭을 생성하고

tab_layout.newTab().setCustomView(tab); 
를 사용하여 사용자 정의보기를 설정

이미 탭이있는 경우 (ViewPager으로 작업한다고 가정 해 보겠습니다), 생성하는 대신 특정 색인에서 탭을 가져올 수 있습니다 의

tab_layout.getTabAt(0).setCustomView(tab); 
+0

한 번 위의 코드를 참조하십시오. –

관련 문제