ToggleButton的用法
来源:互联网 发布:身边的女神自律知乎 编辑:程序博客网 时间:2024/05/20 13:07
XML文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ToggleButton android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/toggleButton" android:textOff="关" android:textOn="开"/> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/imageView2" android:background="@drawable/a1"/></LinearLayout>MainActivity
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.CompoundButton;import android.widget.ImageButton;import android.widget.ImageView;import android.widget.ToggleButton;public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { private ToggleButton tb; private ImageView img; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化控件 tb = (ToggleButton) findViewById(R.id.toggleButton); //设置监听器 tb.setOnCheckedChangeListener(this);//初始化控件img = (ImageView) findViewById(R.id.imageView2); } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { img.setBackgroundResource(isChecked?R.drawable.a2:R.drawable.a1); }}
0 0
- ToggleButton的用法
- ToggleButton的用法
- Android控件ToggleButton的用法
- Android ToggleButton控件的用法
- ToggleButton和Switch的用法
- ToggleButton 用法
- android开发之ToggleButton的用法实现
- ToggleButton Button ImageButton 的区别和用法
- Android中ToggleButton,Switch,SeekBar,RatingBar的一些用法
- ToggleButton的demo
- ToggleButton的使用
- ToggleButton控件的使用
- ToggleButton控件的学习
- ToggleButton控件的学习
- android ToggleButton的使用
- 自定义ToggleButton的样式
- Android的ToggleButton
- ToggleButton的使用
- C语言概述
- spring+httpclient完美集成,封装常用客户端工具类
- Dagger2的使用总结
- Java8-概述
- 窗口看门狗实验
- ToggleButton的用法
- PAT_1042. Shuffling Machine
- HTDP学习笔记(3)--习题5.1.5之我的答案
- git工具的使用方法
- linux redis允许外网ip访问
- Java8-行为参数化
- Win 7 使用 XP的超级终端 hyper terminal
- spring security的ajax提交和json返回数据--兼容form表单提交
- flex 处理商品条单