微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android Studio中Switch控件有关 textOn 和 textOff 用法

 

属性

用法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:gravity="center"
    android:orientation="vertical">

    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textOn="on"
        android:textOff="off"
        android:showtext="true"/>

</LinearLayout>

  需要注意的是,textOn 与 textOff 必须与  android:showtext="true"  一起使用才起作用。

•运行效果

  

自定义Switch 控件textOn和textOff字体大小

  设置 Switch 属性的  android:switchTextAppearance=""  可以达到效果

  在 app/src/res 下找到 values 文件夹,右击->New->Values Resource File,新建一个 style.xml 文件

  添加代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name = "myTextAppearance" parent="@style/TextAppearance.AppCompat.Widget.Switch">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">@color/teal_700</item>
    </style>
    
</resources>

  在上述 <Switch> 控件中添加属性  android:switchTextAppearance="@style/myTextAppearance" ;

  运行效果

  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐