java中:

 public class MainActivity extends Activity implements OnCheckedChangeListener{

     private Switch aSwitch;

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aSwitch = (Switch)findViewById(R.id.switch1);
aSwitch.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
Log.e("", "checked");
}
if(!isChecked){
Log.e("", "not checked");
} }

xml中:

             <Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch1"
android:checked="true" />

注意记住要再onCreate时.setOnCheckedChangeListener(this)

switch控件的使用的更多相关文章

  1. Switch控件详解

    Switch控件详解 原生效果 5.x 4.x 布局 <Switch android:id="@+id/setting_switch" android:layout_widt ...

  2. 在tableviewcell里面嵌入switch控件以及如何获取switch控件数据

    主要是通过cell.accessoryView来添加switch控件- (UITableViewCell *)tableView:(UITableView *)tableView cellForRow ...

  3. Android Studio中Switch控件有关 textOn 和 textOff 用法

    •属性 textOn:控件打开时显示的文字 textOff:控件关闭时显示的文字 showText:设置是否显示开关上的文字(API 21及以上) •用法 <?xml version=" ...

  4. Android Studio中Switch控件有关 thumb 和 track 用法

    •任务 •属性 android:track:底部的图片(灰->绿) android:thumb:设置 Switch 上面滑动的滑块,也就是上图中的白色圆形滑块 •switch_thumb 点击 ...

  5. android switch控件

    <Switch android:layout_width="wrap_content" android:layout_height="@dimen/minCellH ...

  6. ToggleButton控件,Switch控件

    (一) 1.效果图    2. activity_main.xml <?xml version="1.0" encoding="utf-8"?> & ...

  7. android switch控件的使用

    open.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Overridepublic void onCheckedChange ...

  8. 从零开始学ios开发(六):IOS控件(3),Segmented Control、Switch

    这次的学习还是基于上一个项目继续进行(你也可以新建一个项目)学习Segmented Control和Switch. Segmented Control Switch Segmented Control ...

  9. Android自定义控件(一)——开关控件

    Google 在 API 14 开始才新增了Switch 控件. 因此,我们可以选择自己封装一个Switch . 效果如图: View主要代码: public class SwitchView ext ...

随机推荐

  1. JAVA实现IP地址解析

    转载至:http://blog.csdn.net/dragontang/article/details/4151660 http://www.iteye.com/topic/340548#

  2. vs2013 浏览器 browserlink 不停访问

  3. POJ - 2785 - 4 Values whose Sum is 0 - 二分折半查找

    2017-08-01 21:29:14 writer:pprp 参考:http://blog.csdn.net/piaocoder/article/details/45584763 算法分析:直接暴力 ...

  4. 转 : Java的版本特性与历史

    Java Versions, Features and History This article gives you a highlight of important features added i ...

  5. Treflection06_调用静态方法

    1. package reflectionZ; import java.lang.reflect.Method; public class Treflection06 { public static ...

  6. spring mvc : 中文传值(post/get)中文乱码

    请将以下代码放入 web.xml文件中,注意存放顺序,否则会报错.filter应该放在context-param后面: <!-- 字符过滤器 --> <filter> < ...

  7. hive 权限:Authorization failed:No privilege 'Create' found for outputs .

    创建表报错: create table test ( name string ); Authorization failed:No privilege 'Create' found for outpu ...

  8. Updated: EBS 12.1 + Transportable Tablespaces with Incremental Backup Option

    Database migration across platforms of different "endian" (byte ordering) formats using th ...

  9. .html() .text() .val() 的区别

    .html()用为读取和修改元素的HTML标签(包括其Html标签) .text()用来读取或修改元素的纯文本内容 (包括其后代元素) .val()用来读取或修改表单元素的value值.(只能用于表单 ...

  10. redis memcache rabbitMQ

    Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...