ToggleButton作用:用于控制某个View的状态,参数,内容等,使得对应的值循环转换。

使用第一步:
1,在XML之中定于它,并且写上它想控制的视图。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical" >

    <ToggleButton        android:id="@+id/toggle"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:checked="true"        android:textOff="横向排列横向排列"        android:textOn="纵向排列横向排列" />

    <LinearLayout        android:id="@+id/test"        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="wrap_content" >

        <Button            android:id="@+id/btone"            android:layout_weight="1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="按钮一" />

        <Button            android:id="@+id/bttwo"            android:layout_weight="1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="按钮二" />

        <Button            android:id="@+id/btthree"            android:layout_weight="1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="按钮三" />    </LinearLayout>

</LinearLayout>

第二部:在Activity里设置ToggleButton的监听器。

import android.app.Activity;import android.os.Bundle;import android.widget.Button;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.EditText;import android.widget.LinearLayout;import android.widget.ToggleButton;

public class ToggleButtonActivity extends Activity {    private Button button = null;    private EditText editText = null;

  @Override    public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);       setContentView(R.layout.togglebutton);        // Listen for button clicks       ToggleButton toggle=(ToggleButton)findViewById(R.id.toggle);     final LinearLayout test=(LinearLayout)findViewById(R.id.test);       toggle.setOnCheckedChangeListener(new OnCheckedChangeListener(){

          @Override            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {             // TODO Auto-generated method stub                if(arg1){                 //设置LinearLayout垂直布局                  test.setOrientation(LinearLayout.VERTICAL);               }             else{                 //设置LinearLayout水平布局                  test.setOrientation(LinearLayout.HORIZONTAL);             }         }     });   }}

ToggleButton的学习与使用相关推荐

  1. ASP.NET Ajax 控件ToggleButton,SliderExtender,ResizableControl 学习笔记

    ResizableControl ----拖拽控件的大小,,一般用来拖拽图片的大小 (查看效果) 实现代码: <ajaxToolkit:ResizableControlExtender ID=& ...

  2. Android开发学习笔记:浅谈ToggleButton

    ToggleButton(开关按钮)是Android系统中比较简单的一个组件,是一个具有选中和未选择状态双状态的按钮,并且需要为不同的状态设置不同的显示文本. ToggleButton常用的XML属性 ...

  3. ArcGIS API for Silverlight 入门学习笔记(三):基础地图实例

    该实例主要是包含六部分:地图范围.坐标.动画效果.全屏.比例尺.进度条. 前期准备工作 前台代码0 <UserControl x:Class="APIforSilverlightSam ...

  4. Android socket 学习记录 之 执行new socket(ip, port)程序崩溃

    这段时间在学习Android的socket编程,我不是专做APP的,做的是bootloader.驱动.hal.framework这个线的,也就是系统搭建和功能优化设计.为了打通这整条线,为此学习了不少 ...

  5. Silverlight/Windows8/WPF/WP7/HTML5周学习导读(7月30日-8月5日)

    Silverlight/Windows8/WPF/WP7/HTML5周学习导读(7月30日-8月5日) 本周Silverlight学习资源更新 Silverlight 之Control and Use ...

  6. Android Studio --- [学习笔记]RadioButton、CheckBox、ImageView、ListView、TCP的三次握手

    说明 源代码 在2.x里有TCP的三次挥手与四次握手,先对它进行简单的回答(百度).预计在下一篇里,会继续说明TCP 接上一篇: Android Studio - > [学习笔记]Button. ...

  7. 如何学习WPF技术?

    本文由长沙DotNET技术社区[邹溪源]整理,共有7544字,阅读需耗时15分钟. 引言 在桌面开发领域,虽然在某些领域,基于electron的跨平台方案能够为我们带来某些便利,但是由于WPF技术能够 ...

  8. AJAX Control Toolkit 控件学习(转自csdn山巅)

    AJAX Control Toolkit 控件学习 2006-1-16 ToggleButton 关联ASP.NET CheckBox控件 RoundedCorder 造就圆角框 PasswordSt ...

  9. unity 获取预制体_新手如何从零学习unity

    unity的优势就是多终端跨平台打包,入门也快,很多人感觉自己的英不好,就觉得学不会,其实这是一个误区, unity的界面虽然是英文的,但是它的窗口就只有那么几个,用的次数多了,也就自然的熟练 了,那 ...

最新文章

  1. android Camera照相机技术(二)定制拍照
  2. Linux 2.6内核编译与配置安装升级
  3. CCRD_TOC_2008年第6期
  4. 华硕服务器显示模块,华硕远程管理模块 ASMB4-iKVM 华硕服务器主板专用 现货 IPMI...
  5. java writablesheet_jxl加边框,jxl合并单元格,单元格的设置,单元格居中
  6. 【高等数学】高等数学基础理论归纳
  7. MySQL存储过程-2019/7/18
  8. python 列表推导_Python 列表推导式使用的注意事项
  9. Spring官网下载dist.zip的几种方法
  10. OKB突破7.2USDT,再创12月新高
  11. linux java 自启动_Linux设置开机启动脚本
  12. 苏州大学计算机考研大纲2021,2021苏州大学考研参考书目
  13. 腾讯程序员的职业晋升答辩之【完全解析】
  14. kms激活win10
  15. 【社会相关】:大神写的考研政治复习攻略
  16. 浙大 | PTA 习题5-6 使用函数输出水仙花数 (20分)
  17. Junos设备密码恢复
  18. Microsoft Toolkit(win8.1激活工具)v2.5.2 绿色版
  19. ZJOI2019一轮游记
  20. English: date time

热门文章

  1. C++经典算法题-排列组合
  2. 怎么设置wifi网页认证——时讯企业wifi
  3. 华为人报:实事求是科研方向与20年艰苦努力
  4. XEN Crypto创始人分享设计理念及项目愿景
  5. docker使用和搭建
  6. 如何解决wup.exe文件占用cpu资源,彻底删除
  7. C语言二位十进制计算器模数,十进制转二进制计算器
  8. rgba 转 rgb或者16进制的计算方法
  9. 中文编程,最精致的python访客登记系统实例项目,微信机器人不再只当人工智障---08
  10. 翻译之:数据页面和数据行