如何改变切换开关输入文本颜色在XML? [英] how to change switch imput text color in xml?

查看:145
本文介绍了如何改变切换开关输入文本颜色在XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的开关文本在一个XML文件中定义不会改变它的颜色留黑色作为活动背景。我试着用没有任何成功的文本颜色选项。任何想法?

我的xml文件

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:方向=垂直
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:背景=#000000>    <的LinearLayout
        机器人:方向=横向
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT>        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=Hôte酒店
            机器人:文字颜色=#FFFFFF/>
        <的EditText
            机器人:背景=#40FFFFFF
            机器人:ID =@ + ID /主机名
            机器人:layout_width =200像素
            机器人:layout_height =WRAP_CONTENT
            机器人:文字颜色=#FFFFFF/>    < / LinearLayout中>    <的LinearLayout
        机器人:方向=横向
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT>        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=Utiliser https:开头
            机器人:文字颜色=#FFFFFF/>
        <开关
            机器人:ID =@ + ID /开关
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:纹元=上
            机器人:textOff =关闭
            机器人:文字颜色=#FFFFFF
            安卓的onClick =onToggleClicked/>    < / LinearLayout中>
< / LinearLayout中>


解决方案

有关 A 开关,添加到您的 styles.xml 文件:

 <样式名称=X父=@安卓风格/ TextAppearance.Small>
    <项目名称=机器人:文字颜色>#33CCFF< /项目>
< /风格>

两个选项:


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

     的android:switchTextAppearance =@风格/ X


  2. 这您已经创建了开关的实例后,添加到您的Activity类

      switchInstance.setSwitchTextAppearance(getActivity(),R.style.x);


<分> 注意:路径 styles.xml 文件:项目文件夹&GT; RES&GT;值&GT; styles.xml

My text in my switch defined in a xml file won't to change it's color stay black as the activity background. I tried with the textcolor option without any success. Any ideas?

My xml file

<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>

解决方案

For a switch, add this to your styles.xml file:

<style name="x" parent="@android:style/TextAppearance.Small">
    <item name="android:textColor">#33CCFF</item>
</style>

Two options:

  1. add this to your layout XML file:

    android:switchTextAppearance="@style/x"
    

  2. add this to your Activity class after you've created an instance of your switch:

    switchInstance.setSwitchTextAppearance(getActivity(), R.style.x);
    

Note: path to styles.xml file: Project Folder > res > values > styles.xml

这篇关于如何改变切换开关输入文本颜色在XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆