ToggleButton的学习与使用
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的学习与使用相关推荐
- ASP.NET Ajax 控件ToggleButton,SliderExtender,ResizableControl 学习笔记
ResizableControl ----拖拽控件的大小,,一般用来拖拽图片的大小 (查看效果) 实现代码: <ajaxToolkit:ResizableControlExtender ID=& ...
- Android开发学习笔记:浅谈ToggleButton
ToggleButton(开关按钮)是Android系统中比较简单的一个组件,是一个具有选中和未选择状态双状态的按钮,并且需要为不同的状态设置不同的显示文本. ToggleButton常用的XML属性 ...
- ArcGIS API for Silverlight 入门学习笔记(三):基础地图实例
该实例主要是包含六部分:地图范围.坐标.动画效果.全屏.比例尺.进度条. 前期准备工作 前台代码0 <UserControl x:Class="APIforSilverlightSam ...
- Android socket 学习记录 之 执行new socket(ip, port)程序崩溃
这段时间在学习Android的socket编程,我不是专做APP的,做的是bootloader.驱动.hal.framework这个线的,也就是系统搭建和功能优化设计.为了打通这整条线,为此学习了不少 ...
- Silverlight/Windows8/WPF/WP7/HTML5周学习导读(7月30日-8月5日)
Silverlight/Windows8/WPF/WP7/HTML5周学习导读(7月30日-8月5日) 本周Silverlight学习资源更新 Silverlight 之Control and Use ...
- Android Studio --- [学习笔记]RadioButton、CheckBox、ImageView、ListView、TCP的三次握手
说明 源代码 在2.x里有TCP的三次挥手与四次握手,先对它进行简单的回答(百度).预计在下一篇里,会继续说明TCP 接上一篇: Android Studio - > [学习笔记]Button. ...
- 如何学习WPF技术?
本文由长沙DotNET技术社区[邹溪源]整理,共有7544字,阅读需耗时15分钟. 引言 在桌面开发领域,虽然在某些领域,基于electron的跨平台方案能够为我们带来某些便利,但是由于WPF技术能够 ...
- AJAX Control Toolkit 控件学习(转自csdn山巅)
AJAX Control Toolkit 控件学习 2006-1-16 ToggleButton 关联ASP.NET CheckBox控件 RoundedCorder 造就圆角框 PasswordSt ...
- unity 获取预制体_新手如何从零学习unity
unity的优势就是多终端跨平台打包,入门也快,很多人感觉自己的英不好,就觉得学不会,其实这是一个误区, unity的界面虽然是英文的,但是它的窗口就只有那么几个,用的次数多了,也就自然的熟练 了,那 ...
最新文章
- R语言ggplot2可视化绘制分组水平条形图并在条形图的各种位置添加数值标签实战
- anr trace文件分析
- 【Flutter】Flutter 拍照示例 ( 拍照并获取照片源码示例 | image_picker 0.7.2+1 | Flutter 最新 SDK 安装 )
- 转载 干货 | 1400篇机器学习的文章中,这10篇是最棒的!
- 具备什么样的能力,才能在人工智能企业中获得一席之地
- java volatile 基本类型_Java中Volatile关键字详解(转)
- AndroidStudio_安卓原生开发_请求网络图片并解析成BitMap_异步处理_在UI线程执行_利用AsyncTask---Android原生开发工作笔记146
- Java空字符串与null区别
- Atitit 持久化与数据存储标准化规范 目录 1. 存储的附加功能	2 1.1. 基本存取功能	2 1.2. 全文检索(imap	2 1.3. 属性检索	2 1.4. 查询语言	2 2. 基于内容
- cipher命令(转)
- gotoxy函数定义
- PHP合并在线电影ts格式视频文件
- 卡西欧计算机十进制换二进制,卡西欧计算机怎么把十进制转换二进制
- 赛元SC92F7250单片机开发
- 使用终端模拟器通过wifi连接eclipse
- 【Python】WARNING: The script xx.exe is installed in xxdirectory which is not on PATH.
- 淘宝直播全屏页重排算法实践
- “DOTA“巨魔战将连续晕眩的概率
- linux安装firefox
- 亚马逊推出的「距离助手」,好像孙悟空给唐僧画的圈圈啊!