2016-06-28 20 views
1

Ich habe PodCastTab .... Ich möchte vollständig Display TabName ??? Ich frage nicht nach TabHost ?? TabHost und TabLayout anders ... Screenshot von Tabs istWie vergrößert man Tab-Text in TabLayout?

einmal diesen meinen Code sehen:

@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); 

     } 
    }); 
} 

ist das XML-Datei

<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 wie um vollen Tab Text anzuzeigen ??

+0

Mögliche Duplikat von [Ändern Sie die Textgröße in Tab in android] Aufruf (http://stackoverflow.com/questions/19442084/change-the-text-size-in-tab-in -android) – Ironman

Antwort

0

Sie können dies tun durch TabLayout

Zuerst Sie Ihre Registerkarte, wenn nicht aufblasen,

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

und anschließend erstellen Sie einen neuen Tab und stellen Sie eine benutzerdefinierte Ansicht

tab_layout.newTab().setCustomView(tab); 
mit

Beachten Sie, dass Sie, wenn Sie bereits über eine Registerkarte verfügen (z. B. mit einer ViewPager arbeiten), die Registerkarte an einem bestimmten Index abrufen können, anstatt sie zu erstellen ein neues Geschäft von

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

einmal siehe obigen Code –