美文网首页
Switch使用体验

Switch使用体验

作者: 我是你森哥哥 | 来源:发表于2017-06-08 16:06 被阅读0次

介绍

Switch是在4.0以后推出的,所以要注意开发时的minsdk设置,google在API 21后也推出support v7 包下的SwitchCompa的Material Design
开关控件,对低版本的有了更好的的支持。其实switch的应用场景和ToggleButton类似,多应用于两种状态的切换。

<Switch
                    android:id="@+id/is_receive_message"
                    android:layout_width="@dimen/x50"
                    android:layout_height="match_parent"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="@dimen/y10"
                    android:background="@android:color/transparent"
                    android:checked="false"
                    android:textOff=""
                    android:textOn=""
                    android:thumb="@drawable/thumb"
                    android:track="@drawable/track" />

属性介绍
android:typeface="normal":设置字体类型  
android:track="":设置开关的轨迹图片  
android:textOff="开":设置开关checked的文字  
android:textOn="关":设置开关关闭时的文字  
android:thumb="":设置开关的图片  
android:switchMinWidth="":开关最小宽度  
android:switchPadding="":设置开关 与文字的空白距离  
android:switchTextAppearance="":设置文本的风格  
android:checked="":设置初始选中状态  
android:splitTrack="true":是否设置一个间隙,让滑块与底部图片分隔(API 21及以上)  
android:showText="true":设置是否显示开关上的文字(API 21及以上

在代码中使用

 btn_notice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            }
        });

Android UI(Switch)详解 :
http://blog.csdn.net/qq_28057577/article/details/52261641

相关文章

网友评论

      本文标题:Switch使用体验

      本文链接:https://www.haomeiwen.com/subject/vpftqxtx.html