ToggleButton
来源:互联网 发布:linux如何复制命令行 编辑:程序博客网 时间:2024/05/29 14:22
ToggleButton有两种状态,选中和未选中,即开和关,需要在不同状态下显示不同的文本。
属性:
android:checked="true"
android:textOn="开"
android:textOff="关" 具体文本可以自己设置
新建View:
<ToggleButton android:id="@+id/tb1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textOn="开" android:textOff="关" />
<ImageView android:id="@+id/iv1" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/bw2"/>
具体设置:
private ToggleButton tb;private ImageView img;
//ToggleButton 操作tb= (ToggleButton) findViewById(R.id.tb1);img= (ImageView) findViewById(R.id.iv1);//给tb设置监听器tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { //compoundButton 被点击的控件 //b 检测控件状态 img.setImageResource(b?R.drawable.bw1:R.drawable.bw2); }});
同样也可以使用匿名内部类,直接实现接口等方法实现。
如果ImageView设置的是background,则使用img.setBackgroundResourse()
0 0
- ToggleButton
- togglebutton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- ToggleButton
- togglebutton
- ToggleButton
- ToggleButton
- ToggleButton
- Button,ToggleButton
- 预提示TextView
- openSession和getCurrentSession
- 剑指offer(九)之旋转数组的最小数字
- 转载:eclipse中各目录的作用
- 数据流中的中位数
- ToggleButton
- 关于python实现二维数组所有元素求和
- 数组赋值
- Android中的一些开关
- 汇编语言初步理解
- 友元类
- Android布局
- 语音识别中基于规则的语言模型
- Android使用Intent实现页面跳转