Android开关控件ToggleButton
来源:互联网 发布:兼职淘宝模特怎么入行 编辑:程序博客网 时间:2024/09/21 09:02
main.xml如下:
<RelativeLayout 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" tools:context=".MainActivity" > <ToggleButton android:id="@+id/toggleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textOn="打开开关" android:textOff="关闭开关" android:background="@drawable/togglebutton_selector" /></RelativeLayout>
togglebutton_selector.xml如下:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/a" android:state_checked="true"/> <item android:drawable="@drawable/b"/></selector>
mainActivity如下:
package c.c;import android.os.Bundle;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.ToggleButton;import android.app.Activity;/** * Demo描述: * 利用ToggleButton表示状态的改变时 * 并且在状态改变时切换ToggleButton中的文字和图片 * */public class MainActivity extends Activity { private ToggleButton mToggleButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);init();} private void init(){ mToggleButton=(ToggleButton) findViewById(R.id.toggleButton); mToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) {System.out.println("999999999");} else {System.out.println("8888888888");}}}); }}
- Android开关控件ToggleButton
- android中控件ToggleButton开关控件
- android控件 ToggleButton-开关开灯关灯
- Android中的ToggleButton和Switch开关控件
- Android-开关按钮ToggleButton
- Android ToggleButton 开关按钮
- Android ToggleButton(开关)
- 开关控件Switch和ToggleButton
- ToggleButton开关控件的使用
- Android ToggleButton Example--开关按钮
- Android---19---ToggleButton开关按钮
- Android 自定义滑动开关ToggleButton
- Android 滑动开关(ToggleButton) 解析
- 开关按钮控件 ToggleButton 的使用
- ToggleButton状态开关控件的使用
- ToggleButton开关按钮,自定义控件的做法
- 自定义控件——开关按钮ToggleButton
- android控件之ToggleButton
- Android利用StatFs查看SDCard物理信息
- 十秒钟更新完ProgressBar
- IO重要理解及笔记
- UVa 136 - Ugly Numbers
- 利用SoftReference实现图片异步加载
- Android开关控件ToggleButton
- WindowFeature(窗口样式)笔记
- Activity间利用Bundle传递ArrayList
- droiddraw使用方法
- WebView小Demo
- array资源的使用
- DatePicker示例
- 关于计算机图形学的学习
- Android使用系统样式及主题