0

I am implementing a tag layout for my Android application. I tried setting each of the tags to a certain style that has textAllCaps set to false (app:tabTextAppearance="@style/MyCustomTextAppearance")-however, that did not work for me. This question is not a duplicate because I am not using a TabLayout, I am using TabHost. Below is my code:

The style in styles.xml:

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

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        tools:context=".MainActivity"
        app:tabTextAppearance="@style/MyCustomTextAppearance"
        tools:showIn="@layout/activity_main">

        <TabHost
            android:id="@+id/tab_host"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ffffff"
            app:tabTextAppearance="@style/MyCustomTextAppearance"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                app:tabTextAppearance="@style/MyCustomTextAppearance"
                android:orientation="vertical">

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    app:tabTextAppearance="@style/MyCustomTextAppearance"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:id="@+id/tab1"
                        app:tabTextAppearance="@style/MyCustomTextAppearance"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal" />

                    <LinearLayout
                        android:id="@+id/tab2"
                        app:tabTextAppearance="@style/MyCustomTextAppearance"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal" />

                    <LinearLayout
                        android:id="@+id/tab3"
                        app:tabTextAppearance="@style/MyCustomTextAppearance"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal" />
                </FrameLayout>

                <TabWidget
                    android:id="@android:id/tabs"
                    app:tabTextAppearance="@style/MyCustomTextAppearance"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </TabHost>


        <com.anychart.AnyChartView
            android:id="@+id/piechart"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:layout_constraintTop_toBottomOf="@+id/tab_host"
            />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Below is what my app looks like (the text of the tabs are still capitalized): enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Adam Lee
  • 436
  • 1
  • 14
  • 49
  • Does this answer your question? [TabLayout Tab Title text in Lower Case](https://stackoverflow.com/questions/33015652/tablayout-tab-title-text-in-lower-case) – Chintan Soni Nov 06 '19 at 06:01
  • @ChintanSoni It doesn't answer my question because I am using TabHost, not TabLayout. – Adam Lee Nov 06 '19 at 06:03

3 Answers3

0

Apply below style on tabLayout

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

Use this and change style same as color

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
            View v = tabHost.getTabWidget().getChildAt(i);
            v.setBackgroundResource(R.drawable.tabs);

            TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
            tv.setTextColor(getResources().getColor(R.color.white));
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Avinash
  • 867
  • 4
  • 11
0
for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
            View v = tabhost.getTabWidget().getChildAt(i);

            TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
  
            tv.setAllCaps(false);
}
C4F
  • 662
  • 7
  • 18