ToggleButton开关状态按钮控件

一、简介

1、

2、ToggleButton类结构

父类是CompoundButton,引包的时候注意下

二、ToggleButton开关状态按钮控件使用方法

1、新建ToggleButton控件及对象

private ToggleButton toggleButton1;

toggleButton1=(ToggleButton) findViewById(R.id.toggleButton1);

2、设置setOnCheckedChangeListener方法

toggleButton1.setOnCheckedChangeListener(new OnCheckedChangeListener() {})

3、根据是否checked方法实现操作

if(isChecked){//开
  linearLayout1.setOrientation(LinearLayout.VERTICAL);
}
else{//关
  linearLayout1.setOrientation(LinearLayout.HORIZONTAL);
}

三、代码实例

1、效果图:

开状态

关状态

2、代码:

fry.Activity01

 package fry;

 import com.example.ToggleButtonDemo1.R;

 import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.ToggleButton; public class Activity01 extends Activity{
private LinearLayout linearLayout1;
private ToggleButton toggleButton1; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity01); linearLayout1=(LinearLayout) findViewById(R.id.linearLayout1);
toggleButton1=(ToggleButton) findViewById(R.id.toggleButton1);
/*
* ToggleButton开关状态按钮控件使用方法
* 1、新建ToggleButton控件及对象
* 2、设置setOnCheckedChangeListener方法
* 3、根据是否checked方法实现操作
*
*/
toggleButton1.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){//开
linearLayout1.setOrientation(LinearLayout.VERTICAL);
}
else{//关
linearLayout1.setOrientation(LinearLayout.HORIZONTAL);
}
}
}); }
}

/ToggleButtonDemo1/res/layout/activity01.xml

 <?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:orientation="vertical" > <ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textOn="横向排列"
android:textOff="纵向排列"
/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
/>
</LinearLayout> </LinearLayout>

四、获得

1、

android:checked="true"

设置ToggleButton 状态

2、

android:textOn="横向排列"

设置ToggleButton打开文本

3、

toggleButton1.setOnCheckedChangeListener(new OnCheckedChangeListener() {})

设置ToggleButton的setOnCheckedChangeListener方法

4、

if(isChecked)

判断ToggleButton状态开关

ToggleButton开关状态按钮控件的更多相关文章

  1. 重新想象 Windows 8 Store Apps (2) - 控件之按钮控件: Button, HyperlinkButton, RepeatButton, ToggleButton, RadioButton, CheckBox, ToggleSwitch

    原文:重新想象 Windows 8 Store Apps (2) - 控件之按钮控件: Button, HyperlinkButton, RepeatButton, ToggleButton, Rad ...

  2. WinRT自定义控件第一 - 转盘按钮控件

    之前的文章中,介绍了用WPF做一个转盘按钮控件,后来需要把这个控件移植到WinRT时,遇到了很大的问题,主要原因在于WPF和WinRT还是有很大不同的.这篇文章介绍了这个移植过程,由于2次实现的控件功 ...

  3. MFC编程入门之二十三(常用控件:按钮控件的编程实例)

    上一节讲了按钮控件Button.Radio Button和Check Box的基本用法,本节继续讲按钮控件的内容,通过一个实例让大家更清楚按钮控件在实际的软件开发中如何使用. 因为Button控件在前 ...

  4. MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)

    本节继续讲解常用控件--按钮控件的使用. 按钮控件简介 按钮控件包括命令按钮(Button).单选按钮(Radio Button)和复选框(Check Box)等.命令按钮就是我们前面多次提到的侠义的 ...

  5. FineUI第五天---按钮控件

    按钮控件 <x:Button runat="server" ID="按下" Text="按下"></x:Button> ...

  6. VC按钮控件实现指示灯效果

    VC为按钮控件添加图片的方法有很多种: 直接调用SetBitmap:  CButton pButton->SetBitmap(hBitmap); 使用CButtonST控件: 使用CDC: 使用 ...

  7. Qt编写自定义控件11-设备防区按钮控件

    前言 在很多项目应用中,需要根据数据动态生成对象显示在地图上,比如地图标注,同时还需要可拖动对象到指定位置显示,能有多种状态指示,安防领域一般用来表示防区或者设备,可以直接显示防区号,有多种状态颜色指 ...

  8. Qt编写自定义控件9-导航按钮控件

    前言 导航按钮控件,主要用于各种漂亮精美的导航条,我们经常在web中看到导航条都非常精美,都是html+css+js实现的,还自带动画过度效果,Qt提供的qss其实也是无敌的,支持基本上所有的CSS2 ...

  9. 安卓开发_复选按钮控件(CheckBox)的简单使用

    复选按钮 即可以选择若干个选项,与单选按钮不同的是,复选按钮的图标是方块,单选按钮是圆圈 复选按钮用CheckBox表示,CheckBox是Button的子类,支持使用Button的所有属性 一.由于 ...

随机推荐

  1. 第04章—整合Mybatis

    spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...

  2. Java应用多机器部署定时任务解决方案

    Java多机部署下定时任务的处理方案. 本文转自:http://www.cnblogs.com/xunianchong/p/6958548.html 需求: 有两台服务器同时部署了同一套代码, 代码中 ...

  3. Vue中动态添加多个class

    vue中可以通过 :class=""这样来根据一定的条件来动态添加class,但是有时候需要判断的条件比较多,需要动态添加的class也比较多,这个时候其实也很简单 先看一下示例: ...

  4. CNI bridge 插件实现代码分析

    对于每个CNI 插件在执行函数cmdAdd之前的操作是完全一样的,即从环境变量和标准输入内读取配置.这在http://www.cnblogs.com/YaoDD/p/6410725.html这篇博文里 ...

  5. Django框架视图类

    类视图 在写视图的时候,Django除了使用函数作为视图,也可以使用类作为视图.使用类视图可以使用类的一些特性,比如继承等. View django.views.generic.base.View是主 ...

  6. 几分钟私人定制APP全攻略!!

    上网百度了一下什么是自媒体,你会看到这种介绍:自媒体(外文名:We Media)又称"公民媒体"或"个人媒体",是指私人化.平民化.普泛化.自主化的传播者,以现 ...

  7. mysql大数据查询优化

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  8. SAP 后台job

    SAP 如何定义后台job 有两种方 1是se38执行可执行程序后,菜单栏‘程序’--->'后台执行',输入输出设备,ENTER两次后,选择开始时间(立刻执行,或定义日期时间,也可周期执行..) ...

  9. 连接postgresql

    # psycopg2 engine=create_engine('postgresql+psycopg2://scott:tiger@localhost/mydatabase')#  python 连 ...

  10. bootstrap基本使用

    bootstrap是封装了css和js代码实现酷炫的效果,所以使用的时候,比如说是列表效果,直接调用它本身定义的函数就ok了 静态文件 把href='..static/..'里面改为url_for静态 ...