1、简介

  ToggleButton和Switch都是开关按钮,只不过Switch要Android4.0之后才能使用!

ToggleButton
<!--checked 是否选择-->
<!--disabledAlpha 禁用时透明度-->
<!--textOn,textOff 打开/关闭时文字--> Switch
<!--checked 是否选择-->
<!--textOn,textOff 打开/关闭时文字-->
<!--showText 是否显示文字-->
<!--splitTrack 滑块是否和底部图片分隔-->
<!--switchMinWidth 最小宽度-->
<!--track 底部图片-->
<!--thumb 滑块图片-->
<!--typeface 字体四种-->

2、简单使用

  xml布局文件

        <ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="打开"
android:textOff="关闭"
android:id="@+id/toggle"
android:checked="true"
android:disabledAlpha=".5"
/> <!--textOn,textOff 打开/关闭时文字-->
<!--showText 是否显示文字-->
<!--splitTrack 滑块是否和底部图片分隔-->
<!--switchMinWidth 最小宽度-->
<!--track 底部图片-->
<!--thumb 滑块图片-->
<!--typeface 字体四种-->
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="打开"
android:textOff="关闭"
android:showText="true"
android:splitTrack="false"
android:switchMinWidth="100dp"
android:typeface="serif"
android:id="@+id/switch11"
/>

  Java文件,点击事件处理:

        ToggleButton toggleButton = (ToggleButton)findViewById(R.id.toggle);
toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){
Log.d("toggle","打开了");
}else {
Log.d("switch","关闭了");
}
}
}); final Switch switch1 = (Switch)findViewById(R.id.switch11);
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){
Log.d("switch","开了");
}else {
Log.d("switch","关了"); }
}
});

Android基础控件ToggleButton和Switch开关按钮的更多相关文章

  1. Android基础控件ListView基础操作

    1.简介 基于Android基础控件ListView和自定义BaseAdapter适配器情况下,对ListView的数据删除和添加操作: public boolean add(E e) {//添加数据 ...

  2. android 基础控件(EditView、SeekBar等)的属性及使用方法

        android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...

  3. 矩阵, 矩阵 , Android基础控件之ImageView

    天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...

  4. Android基础控件TextClock和Chronometer的使用

    1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...

  5. Android基础控件Button的使用

    1.相关属性 Android的按钮有Button和ImageButton(图像按钮),Button extends TextView, ImageButton extends ImageView! a ...

  6. android基础控件的使用

    控件在屏幕上位置的确定 通常情况下控件在屏幕上确定至少要连接两条线(一条水平,一条垂直) 如下图连接了四条线 辅助线 辅助线的调出: 水平辅助线:进入activity.xml的设计模式之后如下图 为了 ...

  7. android 基础控件 EditText

    EditText 简介: EditText 控件继承 TextView ,它有TextView的所有属性和方法,并且自身是可编辑的: extends TextView java.lang.Object ...

  8. Android 基础控件 TextView

    一TextView介绍: TextView是UI最基本的组件,使用TextView可以显示丰富的文本信息.设置添加TextView最常见的方法就是在xml中添加TextView元素,并指定属性.Tex ...

  9. Android基础控件ProgressBar进度条的使用

    1.简介 ProgressBar继承与View类,直接子类有AbsSeekBar和ContentLoadingProgressBar, 其中AbsSeekBar的子类有SeekBar和RatingBa ...

随机推荐

  1. 2019-4-29-WPF-如何判断一个控件在滚动条的里面是用户可见

    title author date CreateTime categories WPF 如何判断一个控件在滚动条的里面是用户可见 lindexi 2019-4-29 9:42:2 +0800 2019 ...

  2. JS对象 提取指定数目的字符substr() substr() 方法从字符串中提取从 startPos位置开始的指定数目的字符串。

    提取指定数目的字符substr() substr() 方法从字符串中提取从 startPos位置开始的指定数目的字符串. 语法: stringObject.substr(startPos,length ...

  3. VBA文件对话框的应用(VBA打开文件、VBA选择文件、VBA选择文件夹)

    在VBA中经常要用到文件对话框来进行打开文件.选择文件或选择文件夹的操作.用Microsoft Office提供的文件对话框比较方便.用法如下Application.FileDialog(fileDi ...

  4. Elasticsearch.net一些开发笔记

    .net下开发es半年多了,留下些笔记 //https://www.elastic.co/guide/cn/elasticsearch/guide/current/combining-filters. ...

  5. WifiManager Wifi 管理器&&知识点

    WifiManager 主要使用的技术: SimpleWifi,MahaApp.Metro控件 一 网卡设置 1.获取所有网卡(NetWorkAdapter类) 方法A 通过API SELECT * ...

  6. 关于 wpf 的ICommand 的 CanExecute CanExecuteChanged func action的认识

    关于 wpf 的ICommand 的 CanExecute CanExecuteChanged  func  action的认识

  7. 校园商铺-2项目设计和框架搭建-10验证controller

    1.新建package:com.csj2018.o2o.web.superadmin 2.建立AreaController.java package com.csj2018.o2o.web.super ...

  8. kubernetes监控和性能分析工具:heapster+influxdb+grafana

    1.部署heapster 下载 heapster 相关 yaml 文件 [root@master dashboard]# wget https://raw.githubusercontent.com/ ...

  9. Parse-轻松构建移动APP的后台服务

    目前正在开发的产品告一段落,有时间总结下经验,也顺便分享一下我们主要使用的平台-Parse. 什么是Parse?  Parse是一群美国人开发的专为移动APP服务的云计算平台,与现有的其他云计算平台相 ...

  10. class.forname & classloader

    From https://www.cnblogs.com/gaojing/archive/2012/03/15/2413638.html 传统的使用jdbc来访问数据库的流程为: Class.forN ...