zoukankan      html  css  js  c++  java
  • Android 多状态按钮 ToggleButton

    ToggleButton
         选中状态,未选中状态并且需要为不同的状态设置不同的显示文本。
         属性:
              checked="true"
              textOff=""
              textOn=""
     
    private ToggleButton tb ;
    private ImageView iv ;
         tb=(ToggleButton) findViewById(R.id.toggleButton1);
          iv=(ImageView) findViewById(R.id. imageView1);
          //给togglebutton 设置监听器
          tb.setOnCheckedChangeListener( new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
               /*
                *  当TB被点击的时候,当前的方法会被执行
                *  buttonView  代表被点击的控件的本事(对象)
                *  isChecked  代表被点击的控件的状态(On/Off)
                */
                 iv.setImageResource(isChecked?R.drawable. on:R.drawable.ic_launcher);
             }
          });
         
     
     
     
     <ToggleButton
            android:id="@+id/toggleButton1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textOn="@string/textOn"
            android:textOff="@string/textOff"
            android:hint="@string/ToggleButton" />
     
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:src="@drawable/ic_launcher" />
    stareblankly.cn
  • 相关阅读:
    九种常用排序的性能分析总结
    C语言输出格式总结
    线程安全的单例模式
    反射原理
    二进制的计算(计算机为什么采用补码存储数据)
    java程序员必须会的技能
    09网易校园招聘笔试题
    Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式
    【转】策略与机制分离
    VM PowerCli的简单安装和使用学习
  • 原文地址:https://www.cnblogs.com/stareblankly/p/4829249.html
Copyright © 2011-2022 走看看