我在 xml 文件中定义的 switch
中的文本不会改变它的颜色保持黑色作为 Activity 背景。我尝试使用 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>
最佳答案
对于 switch
,将其添加到您的 styles.xml
文件中:
<style name="x" parent="@android:style/TextAppearance.Small">
<item name="android:textColor">#33CCFF</item>
</style>
两种选择:
将此添加到您的布局
XML
文件中:android:switchTextAppearance="@style/x"
在您创建了您的
开关
实例之后,将其添加到您的 Activity 类中:switchInstance.setSwitchTextAppearance(getActivity(), R.style.x);
注意styles.xml
文件的路径:Project Folder > res > values > styles.xml
关于android - 如何更改 xml 中的开关输入文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17974305/