•属性

  • textOn:控件打开时显示的文字

  • textOff:控件关闭时显示的文字

  • showText:设置是否显示开关上的文字(API 21及以上)

•用法

<?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" ;

  运行效果:

  

Android Studio中Switch控件有关 textOn 和 textOff 用法的更多相关文章

  1. Android Studio中Switch控件有关 thumb 和 track 用法

    •任务 •属性 android:track:底部的图片(灰->绿) android:thumb:设置 Switch 上面滑动的滑块,也就是上图中的白色圆形滑块 •switch_thumb 点击 ...

  2. Android线程中设置控件

    在Android中经常出现多线程中设置控件的值报错的情况,今天教大家封装一个简单的类避免这样的问题,同样也调用实现也非常的方便. 自定义类: /** * Created by wade on 2016 ...

  3. android include中的控件调用

    项目中经常会有一些布局是重用的,但是如何来更好的利用这些布局中的控件 转: http://zhidao.baidu.com/link?url=GU93U8Wu31dfp7mKEx52hMJkxjFLC ...

  4. Android Studio自定义组合控件

    在Android的开发中,为了能够服用代码,会把有一定共有特点的控件组合在一起定义成一个自定义组合控件. 本文就详细讲述这一过程.虽然这样的View的组合有一个粒度的问题.粒度太大了无法复用,粒度太小 ...

  5. visual studio中验证控件的使用

    1.RequiredFieldValidator:验证一个必填字段,如果这个字段没填,那么,将不能提交信息. RequiredFieldValidator控件中,主要设置三个属性: (1)ErrorM ...

  6. Android View中的控件和监听方法...

    PS:居然三天没写博客了...今天补上...东西虽多,但是都是一些基础...代码多了一些,有人可能会这样问,粘这么多代码有毛用..其实对于一个Android的初学者来说,一个完整的代码是最容易帮助理解 ...

  7. Android Studio 学习 - 基本控件的使用;Intent初学

    Android Studio学习第三天. 今天主要学习 1. RadioButton.CheckBox.RatingBar.SeekBar等基础控件的使用. 结合Delphi中相类似的控件,在这些基本 ...

  8. Android Studio中Button等控件的Text中字符串默认大写的解决方法

    初学Android的时候,在Android Studio中xml里面添加一个Button.EditText等控件后,它的Text总是会显示大写,即使你输入的字符串是小写也不行,控制字符串大小写的属性是 ...

  9. Android 中常见控件的介绍和使用

    1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...

随机推荐

  1. event duplication bind bug & h5 dataset flag solution

    event duplication bind bug & h5 dataset flag solution https://codepen.io/xgqfrms/full/PaRBEy/ OK ...

  2. Flutter for web

    Flutter for web https://flutter.dev/web https://github.com/flutter/flutter_web Dart https://github.c ...

  3. javascript disable scroll event

    javascript disable scroll event Document: scroll event https://developer.mozilla.org/en-US/docs/Web/ ...

  4. wireshark 获取指定进程id的数据

    >netstat -aon | findstr 11380 TCP 191.127.1.7:57936 29.225.107.216:3734 ESTABLISHED 11380 过滤器: tc ...

  5. Scrapy 项目:腾讯招聘

    目的: 通过爬取腾讯招聘网站(https://careers.tencent.com/search.html)练习Scrapy框架的使用 步骤: 1.通过抓包确认要抓取的内容是否在当前url地址中,测 ...

  6. css选择器,过滤筛选

    $('.required:not(.final_price)').each(function() { if (!$(this).val()) { error_count ++; if ($(this) ...

  7. call、apply和bind的实现

    call方法 基础版, 只能修改指向,不能传参 Function.prototype.myCall = function(context) { // 获取调用者,这里为bar context.fn = ...

  8. 图文详解:Kafka到底有哪些秘密让我对它情有独钟呢?

  9. Redis与Spring Data Redis

    1.Redis概述 1.1介绍 官网:https://redis.io/ Redis是一个开源的使用ANSIC语言编写.支持网络.可基于内存 亦可持久化的日志型.Key-Value型的高性能数据库. ...

  10. Docker Hub 镜像加速器

    一.概述 国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器.Docker 官方和国内很多云服务商都提供了国内加速器服务. 二.配置加速地址 Ubuntu 16.04+.De ...