Android控件ToggleButton的使用方法
ToggleButton经常使用的XML属性
属性名称 |
描写叙述 |
android:disabledAlpha |
设置button在禁用时透明度。 |
android:textOff |
未选中时button的文本 |
android:textOn |
选中时button的文本 |
main.xml:
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent" android:background="#FFF5F5F5"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:textSize="14.0sp" android:id="@+id/tvSound" android:textColor="@android:color/black"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="已开启" />
<ToggleButton
android:id="@+id/tglSound" android:background="@drawable/selector_butn_toggle"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:textOn="" android:textOff=""
android:text="" />
</LinearLayout>
</LinearLayout>
MainActivity.java:
package com.apkbus.toggle; import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
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 mToggleButton;
private TextView tvSound;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
setContentView(R.layout.main);
initView();//初始化控件方法
} private void initView() {
mToggleButton = (ToggleButton) findViewById(R.id.tglSound); //获取到控件
mToggleButton.setOnCheckedChangeListener(this);//加入监听事件
tvSound = (TextView) findViewById(R.id.tvSound);
} @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
tvSound.setText("已开启");
}else{
tvSound.setText("已关闭");
}
}
}
效果图:


Android控件ToggleButton的使用方法的更多相关文章
- android控件 ToggleButton的应用
ToggleButton是android给我们提供的开关按钮, 有两种状态:选中和未选择状态. 以下是代码实例: main.xml [html] view plain copy <?xml ve ...
- Android 控件EditText的setOnEditorActionListener方法的理解
需要注意的是 setOnEditorActionListener这个方法,并不是在我们点击EditText的时候触发,也不是在我们对EditText进行编辑时触发,而是在我们编辑完之后点击软键盘上的回 ...
- Android控件——ToggleButton多状态按钮(实现灯泡的开关)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxoAAAFxCAIAAAB7jkm1AAAgAElEQVR4nOy9eXgUVb7/Dy7j3BnH8T
- xe6 android控件透明度设置方法
今天才知道xe6 android控件的透明度设置方法:只需设置控件中的Opacity参数,默认为1--不透明 panel1.Opacity:=0.60;
- Android应用之——自己定义控件ToggleButton
我们经常会看到非常多优秀的app上面都有一些非常美丽的控件,用户体验非常好.比方togglebutton就是一个非常好的样例,IOS系统以下那个精致的togglebutton现在在android以下也 ...
- UIAutomator定位Android控件的方法
UIAutomator各种控件定位的方法. 1. 背景 使用SDK自带的NotePad应用,尝试去获得在NotesList那个Activity里的Menu Options上面的那个Add note菜单 ...
- 【转】UIAutomator定位Android控件的方法实践和建议(Appium姊妹篇)
原文地址:http://blog.csdn.net/zhubaitian/article/details/39777951 在本人之前的一篇文章<<Appium基于安卓的各种FindEle ...
- UIAutomator定位Android控件的方法实践和建议(Appium姊妹篇)
在本人之前的一篇文章<<Appium基于安卓的各种FindElement的控件定位方法实践和建议>>第二章节谈到Appium可以通过使用UIAutomator的方法去定位And ...
- Android控件介绍
1. 介绍 Android控件大多位于android.widget, android.view.View为他们的父类对于Dialog系列, android.app.Dialog为父类 Android的 ...
随机推荐
- Java中泛型的各种使用
Java中的泛型的使用: 1.普通的泛型使用 在使用类的时候后面的<>中的类型就是我们确定的类型. public class MyClass1<T> {//此处定义的泛型是T ...
- LBP(Local Binary Patterns)局部二进制模式
1. LBP 用于人脸识别 为了预测每个像素属于哪个脸部器官(眼睛.鼻子.嘴.头发),通常的作法是在该像素周围取一个小的区域,提取纹理特征(例如局部二值模式),再基于该特征利用支持向量机等浅层模型分类 ...
- 用jquery给select加选中事件
select在前端开发过程中很常用,现在我们要实现一个效果,那就是选中select中的某一项,执行事件,本来自己没怎么接触过这些,最后网上找了一些资料,自己研究了一下,把方法分享给大家,大家如果有需要 ...
- Android带弹性的View
在Android开发中ListView.ScrollView用到的频率相当高,可是一个优秀的应用我们能看到它里面的效果绝对不会那么死板,安卓原生的ListView和ScrollView都不能满足这个要 ...
- 查询SqlServer最近执行过的Sql
SELECT TOP 1000ST.text AS '执行的SQL语句' ,QS.execution_count AS '执行次数' ,QS.total_elapsed_time / 10000 AS ...
- spinlock参考资料
spinlock:http://irl.cs.ucla.edu/~yingdi/web/paperreading/smp_locking.pdf
- mac ssh报错处理
总结一下 1.The authenticity of host '[192.168.1.100]:22 ([192.168.1.100]:22)' can't be established. RSA ...
- javascript上下文this
js的四种调用方式: 一 作为函数的调用: 在严格模式下this,undefined,在非严格模式下指向全局window对象. 二 作为方法调用: this通常指向调用的对象 三 作为构造函数的调用: ...
- php实现自动加载类
PHP 实现自动加载类:
- NodeJS学习笔记 (29)二进制解码-string_decoder(ok)
原文:https://github.com/chyingp/nodejs-learning-guide 自己过一遍: 模块简介 string_decoder模块用于将Buffer转成对应的字符串.使用 ...