位置: 编程技术 - 正文

ToggleButton开关按钮(toggle button什么作用)

编辑:rootadmin
1.先在xml文件添加一个控件ToggleButton并设置相关属性: android:textOn="开时显示的文字" android:textOff="关时显示的文字"

推荐整理分享ToggleButton开关按钮(toggle button什么作用),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:toggle buttons,togglebutton用法,toggle botton,toggle botton,toggle buttons,buttontoggled,togglebutton开关按钮,toggle buttons,内容如对您有帮助,希望把文章链接给更多的朋友!

android:checked="默认状态是开是关"

2.在MainActivity文件里定义一个ToggleButton控件并实例化,实现ToggleButton控件的监

if(arg1)

{开时要实现的操作}else{关时要实现的操作ToggleButton开关按钮(toggle button什么作用)

}

3.详见源代码

<LinearLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ToggleButton android:id="@&#;id/mytb" android:layout_width="match_parent" android:layout_height="wrap_content" android:textOn="开" android:textOff="关" android:checked="false"/> <TextView android:id="@&#;id/mytv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开关关闭了" /> </LinearLayout>

package com.example.togglebutton;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.TextView;import android.widget.ToggleButton;public class MainActivity extends Activity implements OnCheckedChangeListener{private ToggleButton mytb;private TextView mytv;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mytb=(ToggleButton) findViewById(R.id.mytb);mytv=(TextView) findViewById(R.id.mytv);mytb.setOnCheckedChangeListener(this);}@Overridepublic void onCheckedChanged(CompoundButton arg0, boolean arg1) {// TODO Auto-generated method stubif(arg1){mytv.setText("开关打开了");}else{mytv.setText("开关关闭了");}}}

安卓完美退出App以及跨界面关闭Activity 在安卓项目中,当有多个App时,通过StarActivity方法带参数可以在另一个Activity可以将前一个Activity关闭掉,但是有一个局限,就是跳转了多个Activity之后

Open quote is expected for attribute "name" associated with an element type "item". 最近写安卓代码的时候Eclipse报错:Openquoteisexpectedforattributenameassociatedwithanelementtypeitem.错误代码:stylename=AppThemeparent=AppBaseThemeitemname=android:windowNoTitletrue/

Java Curl 开发记录(三) 使用ndk编译libcurl 昨天将libcurljava的封装写完,今天继续将libcurl移植到Android。首先下载curl,我下载的是7..0这个版本(不是最新版本)。我使用的是ubuntu.位,下载

本文链接地址:https://www.jiuchutong.com/biancheng/374418.html 转载请保留说明!

上一篇:android Fragment 入门介绍(android fragmentation)

下一篇:安卓完美退出App以及跨界面关闭Activity(android 退出app)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络