ToggleButton的使用
2016-10-27 22:18
78 查看
废话不说,来看看我们要使现的效果
常用属性:
android:button 背景样式
android:textOff 未选中按钮的文本
android:textOn 选中时的文本
android:disabledAlpha 按钮禁用时的透明度
一:xml文件
<ToggleButton
android:id="@+id/togglebutton2"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:background="@null"
android:button="@drawable/chen_select_home_set_button"
android:textOff=""
android:textOn=""
android:visibility="visible" />
二:selector文件 chen_selec_home_set_button.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_home_set_on" android:state_checked="true"/>
<item android:drawable="@drawable/icon_home_set_off" android:state_checked="false"/>
</selector>
三:java
@OnClick({ R.id.tv_set_three, R.id.tv_set_title, R.id.togglebutton2 })
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_set_title:
finish();
break;
// 打开关闭推送
case R.id.togglebutton2:
int a = 0;
常用属性:
android:button 背景样式
android:textOff 未选中按钮的文本
android:textOn 选中时的文本
android:disabledAlpha 按钮禁用时的透明度
一:xml文件
<ToggleButton
android:id="@+id/togglebutton2"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:background="@null"
android:button="@drawable/chen_select_home_set_button"
android:textOff=""
android:textOn=""
android:visibility="visible" />
二:selector文件 chen_selec_home_set_button.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_home_set_on" android:state_checked="true"/>
<item android:drawable="@drawable/icon_home_set_off" android:state_checked="false"/>
</selector>
三:java
@OnClick({ R.id.tv_set_three, R.id.tv_set_title, R.id.togglebutton2 })
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_set_title:
finish();
break;
// 打开关闭推送
case R.id.togglebutton2:
int a = 0;
<span style="white-space:pre"> </span>//判断是否选中 if (togglebutton2.isChecked()) { //选中 点击恢复按钮后,极光推送服务会恢复正常工作 JPushInterface.resumePush(getApplicationContext()); } else { //未选中 点击停止按钮后,极光推送服务会被停止掉 JPushInterface.stopPush(getApplicationContext()); } break;
相关文章推荐
- BB10 Cascades: ToggleButton的使用
- 双状态按钮控件ToggleButton的使用
- 使用Scroller制作滑块开关ToggleButton
- ToggleButton的使用
- ToggleButton的使用
- 使用ToggleButton按钮实现开关效果
- ToggleButton,Switch,RatingBar的使用
- 安卓开发中ToggleButton按钮的使用
- 自定义ToggleButton--温馨效果-xml中使用代码写监听就好
- android中ToggleButton的使用
- 开关按钮控件 ToggleButton 的使用
- togglebutton的使用(开关按钮)改变布局的方式
- Android成长日记-使用ToggleButton实现灯的开关
- ToggleButton开关按钮的使用
- ToggleButton的使用
- [Android实例] eoe & 友盟教程大赛【ToggleButton使用教程】
- android中使用自定义控件checkbox,ToggleButton,ProgressBar
- 使用ToggleButton
- android:onClick属性使用之ToggleButton
- ListView中的每个Item嵌套使用ToggleButton