开关按钮(ToggleButton&Switch)
开关按钮,很实用的小东西。
下面上实例:
-------------------------------我是邪恶的分割线---------------------------------------
1.java代码
package gdp.switchtestv1; import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton; public class MainActivity extends Activity {
private ToggleButton toggle;
private Switch switcher;
private LinearLayout test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //获取空间对象
toggle=(ToggleButton)findViewById(R.id.toggle);
switcher=(Switch)findViewById(R.id.switcher);
test=(LinearLayout)findViewById(R.id.test); //绑定监听器
toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
test.setOrientation(1);
}else{
test.setOrientation(0);
}
}
}); switcher.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
test.setOrientation(1);
}else{
test.setOrientation(0);
}
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
2.xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- texton表示开关打开状态显示的文本,textoff表示开关关闭状态显示的文本 -->
<!-- checked属性为默认开关所处的状态 -->
<ToggleButton
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="on"
android:textOff="off"
android:checked="true"
/>
<Switch
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="on"
android:textOff="off"
android:checked="true"
/>
<LinearLayout
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="bn1"
/>
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="bn2"
/>
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="bn3"
/>
</LinearLayout> </LinearLayout>
开关按钮(ToggleButton&Switch)的更多相关文章
- Android学习笔记-开关按钮ToggleButton和开关Switch
		
本节给大家介绍的Android基本UI控件是:开关按钮ToggleButton和开关Switch,这两个其实都是开关组件,只是后者需要在Android 4.0以后才能使用 所以AndroidManif ...
 - Android——滚动视图(ScrollView)图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟
		
xml <?xml version="1.0" encoding="utf-8"?> <!--滚动视图--> <ScrollVie ...
 - android基本控件学习-----ToggleButton&Switch
		
ToggleButton(开关按钮)和Switch(开关)讲解: 一.核心属性讲解: (1)ToggleButton textOn:按钮被选中的时候文字显示 textOff:按钮没有被选中的时候文字显 ...
 - 状态开关按钮(ToggleButton)和开关(Switch)
		
ToggleButton支持的XML属性及相关方法1.android:checked----->setChecked(boolean) ----->设置该按钮是否被选中2.android: ...
 - iOS的settings bundle中开关按钮(Toggle Switch)取不到值的问题
		
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 在Xcode7.2中设置App的settings bundle ...
 - Android——图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟、图片透明度、滚动和时间选择器
		
activity_ui1.xml dth="wrap_content" android:layout_height="wrap_content" android ...
 - PyQt4开关按钮ToggleButton
		
PyQt4没有开关按钮部件.但是我们可以使用在特殊状态下的QPushButton部件来创建开关按钮.而所谓的开关按钮就是一个具有按下和未按下两种状态的普通赶牛.用户可以通过单击按钮来切换其开或者关的状 ...
 - ToggleButton与Switch
		
状态开关按钮togglebutton和开关switch 状态开关按钮togglebutton和开关switch是由button派生出来的,本质也是按钮,支持BUtton的各种属性,从功能上看,Togg ...
 - Android ToggleButton Example--开关按钮
		
Android ToggleButton Example 在 Android 中, “android.widget.ToggleButton” 是个特殊的类,可以渲染出一个“开关按钮” ,顾名思义, ...
 
随机推荐
- Fix error of "you have been logged on with a temporary profile"
			
You have been logged on with a temporary profile on windows2008 R2 After looking into this issue, I ...
 - 各版本Sql Server下载地址全
			
SQL Server 2014简体中文企业版 文件名:cn_sql_server_2014_enterprise_edition 32位下载地址:ed2k://|file|cn_sql_server_ ...
 - lxml.html删除节点树和tag对
			
# encoding: utf-8import StringIO from apihelper import info, info_savefrom lxml import etree, htmlfr ...
 - UVALIVE 3031  Cable TV Network
			
题意:求点联通度 首先看了别人的题解还是不晓得只枚举汇点的原因觉得行不通 关于求点联通度的建图方法 转自http://hi.baidu.com/lerroy312/item/5a5f36f2f5bba ...
 - PHP-MYSQL时间
			
Unix 时间戳 Unix timestamp ('1970-01-01 00:00:00' GMT 之后的秒数) MySQL: FROM_UNIXTIME() 给定一个Unix 时间戳 (可以是 ...
 - kubernetes 搭建集群外部ip服务
			
nginx-pod.yaml apiVersion: v1 kind: Pod metadata: name: webapp labels: app: webapp spec: containers: ...
 - centos tc 端口限速
			
#http://www.fx114.net/qa-178-108967.aspx#http://professor.blog.51cto.com/996189/1569481/#http://blog ...
 - docker入门之:centos6.5 安装docker
			
centos6.5 : 使用EPEL库安装docker: # sudo yum install -y http://mirrors.yun-idc.com/epel/6/i386/epel-rele ...
 - Android应用开发之使用Socket进行大文件断点上传续传
			
http://www.linuxidc.com/Linux/2012-03/55567.htm http://blog.csdn.net/shimiso/article/details/8529633 ...
 - Netty源码学习(七)FastThreadLocal
			
0. FastThreadLocal简介 如同注释中所说:A special variant of ThreadLocal that yields higher access performance ...