androidxml:Style-TabHost具有小写文本

androidxml:Style-TabHost具有小写文本,android,android-layout,android-styles,Android,Android Layout,Android Styles,我正在为我的Android应用程序实现一个标签布局。我尝试将每个标记设置为某个样式,该样式将textAllCaps设置为false(app:tabTextAppearance=“@style/MyCustomTextAppearance”)-但是,这对我不起作用。这个问题不是重复的,因为我不是在使用TabLayout,而是在使用TabHost。下面是我的代码: styles.xml中的样式: <style name="MyCustomTextAppearance" parent="Text

我正在为我的Android应用程序实现一个标签布局。我尝试将每个标记设置为某个样式,该样式将
textAllCaps
设置为
false
app:tabTextAppearance=“@style/MyCustomTextAppearance”
)-但是,这对我不起作用。这个问题不是重复的,因为我不是在使用TabLayout,而是在使用TabHost。下面是我的代码:

styles.xml中的样式:

<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
</style>
<?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>

假的
content\u main.xml

<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
</style>
<?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>


在表格布局上应用以下样式

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

使用此选项并更改与颜色相同的样式

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));
}
for(int i=0;i
for(int i=0;i
这是否回答了您的问题@ChintanSoni它没有回答我的问题,因为我使用的是TabHost,而不是TabLayout。