如何在xml中更改切换输入文本颜色?

Wil*_*ld7 4 xml android textcolor switch-statement

我在switchxml文件中定义的文本不会改变它的颜色保持黑色作为活动背景.我尝试使用textcolor选项但没有成功.有任何想法吗?

在此输入图像描述

我的xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hôte : "
            android:textColor="#FFFFFF"/>
        <EditText 
            android:background="#40FFFFFF"
            android:id="@+id/hostname"
            android:layout_width="200px"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"/>

    </LinearLayout>

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Utiliser Https : "
            android:textColor="#FFFFFF"/>
        <Switch 
            android:id="@+id/Switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textOn="on"
            android:textOff="off"
            android:textColor="#FFFFFF"
            android:onClick="onToggleClicked"/>

    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Mic*_*ski 10

对于a switch,将其添加到您的styles.xml文件中:

<style name="x" parent="@android:style/TextAppearance.Small">
    <item name="android:textColor">#33CCFF</item>
</style>
Run Code Online (Sandbox Code Playgroud)

两种选择:

  1. 将其添加到您的布局XML文件中:

    android:switchTextAppearance="@style/x"
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在创建了以下实例后,将其添加到Activity类switch:

    switchInstance.setSwitchTextAppearance(getActivity(), R.style.x);
    
    Run Code Online (Sandbox Code Playgroud)

注意:styles.xml文件路径:Project Folder > res > values > styles.xml