Change the text size in tab in android

谁说我不能喝 提交于 2019-11-27 15:43:10
Dinesh Raj
TextView x = (TextView) tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title);
    x.setTextSize(25);

refer the below link for more detail

Change text size on tabHost

How to change the font size of tabhost in android

You can use the TabLayout and Viewpager instead, and set the tabMode to scrollable, see code below:

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="center"
        app:tabMode="scrollable" />
 app:tabMode="scrollable"
 app:tabGravity="fill"

Use this line in your tab xml and it will do it.

You can also customize the text and background of a your tabs. See this blog for a very good tutorial on how to do it.

Easy wasy to do Just add style to ur xml file declare the size in which you want.

<style name="CustomTheme" parent="@android:style/Theme">
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
    <item name="android:textAppearance">@style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" 
    parent="@android:style/TextAppearance.Widget.TabWidget">
    <item name="android:textSize">100sp</item>
    <item name="android:textStyle">**strong text**</item>
</style>

Dont forget to add theme with style name in manifast file.

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

Use app:tabMode="scrollable"

Just put the TabLayout inside a HorizontalScrollView:

<HorizontalScrollView
             android:layout_width="match_parent"
             android:layout_height="wrap_content">
                <android.support.design.widget.TabLayout
                 android:id="@+id/tabs"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" />
    </HorizontalScrollView>
viral 9966
<TabHost
     android:id="@+id/tabhost"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_alignParentLeft="true">

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical" >

         <TabWidget
             android:id="@android:id/tabs"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             >

         </TabWidget>


         <FrameLayout
             android:id="@android:id/tabcontent"
             android:layout_width="0dp"
             android:layout_height="0dp"
             android:layout_weight="0" />

         <android.support.v4.view.ViewPager
             android:id="@+id/viewpager"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             />
     </LinearLayout>
 </TabHost>

Code:

for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
{
    TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
    tv.setTextColor(Color.parseColor(SM.getTheme_colour()));
    tv.setTypeface(font_k);
}

This code works for tabhost change text color, type face (font style) and also text size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!