您的位置:首页 > 其它

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;
<span style="white-space:pre">			</span>//判断是否选中
if (togglebutton2.isChecked()) {

//选中  点击恢复按钮后,极光推送服务会恢复正常工作
JPushInterface.resumePush(getApplicationContext());
} else {
//未选中 点击停止按钮后,极光推送服务会被停止掉
JPushInterface.stopPush(getApplicationContext());
}
break;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ToggleButton