当前位置:网站首页>ToggleButton(按钮开关)
ToggleButton(按钮开关)
2022-07-27 17:02:00 【Ashurol】
public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{
ToggleButton tb;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tb=(ToggleButton) findViewById(R.id.toggleButton1);
img=(ImageView) findViewById(R.id.imageView1);
tb.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
// TODO Auto-generated method stub
//isChecked代表被点击的状态
Toast.makeText(this, isChecked+"", 0).show();
if(isChecked==true)
{
img.setBackgroundResource(R.drawable.caidan2);
}else{
img.setBackgroundResource(R.drawable.caidan1);
}
}
}<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.xin.togglebutton.MainActivity" >
<ToggleButton
android:checked="false"
android:id="@+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="开"
android:textOff="关" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/caidan1" />
</LinearLayout>

边栏推荐
- 估值超156亿元!华勤通讯完成10亿元B轮融资!高通创投、英特尔资本领投
- Adhering to the integration of software and hardware, one Hengke makes efforts to the intelligent educational robot market
- 开启和禁用hyper-v
- 【深度学习基础知识 - 47】贝叶斯网络与朴素贝叶斯
- 下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增
- C language: 11. Pipeline
- Big guys, Oracle CDC, local operation, always encounter this an exception occurred in
- 【深度学习基础知识 - 39】BN、LN、WN的比较
- 【深度学习目标检测系列 - 01】目标检测是什么
- Fzu1669 right angled triangle
猜你喜欢

c语言:7、c语言多源码文件使用方法

5W bonus pool / for colleges and universities, 2022 legal science and technology innovation competition is in progress

C language: 7. How to use C language multi source files

C language: C language code style

带来高价值用户体验的低代码开发平台

Take byte offer in four rounds and answer the interview questions

Map和Set

Introduction to Flink operator

High cost, difficult to implement, slow to take effect, what about open source security?

S32K系列芯片--简介
随机推荐
开启和禁用hyper-v
C language: 6. Simple use and precautions of pointer
【深度学习基础知识 - 40】CNN为什么比DNN在图像领域更具优势
Release Samsung 3J1 sensor: the code implies that the safety of pixel 7 face recognition will be greatly increased
技术实践干货 | 初探大规模 GBDT 训练
英特尔发布Horse Ridge芯片:22nm工艺,能够控制多个量子位
爱立信承认在中国等五国行贿,向美支付10.6亿美元罚款
Fzu1669 right angled triangle
估值超156亿元!华勤通讯完成10亿元B轮融资!高通创投、英特尔资本领投
【日常积累 - 07】cuda多版本切换
Programming jump
Dry goods of technical practice | preliminary exploration of large-scale gbdt training
MFC高级控件之Tab控件( CTabCtrl )
Count the six weapons of the domestic interface cooperation platform!
首发骁龙765G!Redmi K30 5G版发布:支持5G双模120Hz屏,定价1999元起
FZU1669 Right-angled Triangle【毕达哥拉斯三元组】
c语言:clion调试方法
Flink 算子简介
A lock faster than read-write lock. Don't get to know it quickly
c语言:6、指针的简单使用与注意事项