手机jquery 滑动开关按钮时怎么会黑幕

查看其它类似图标
滑动开关图标有的时候手机屏不停地闪烁按键子都不好使,按开关后再开屏。等会就好了。这是怎么回事
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因&
已有2个回答
[特聘专家]
专家星级&:&2.7星
问答堂专家综合评分
问题评分&:&4.9星
采纳、点赞&:&0星
二次回复率&:&0星
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
和屏幕没有关系,这种情况很明显是电源干扰,进水重摔都会造成这种情况,也有可能是主板老化,建议到维修点检测下,用不了50元。我的老手机也是这样,感觉是线路老化,屏幕带电不均匀导致的。
留下你的评论
[编辑专家]
专家星级&:&1.8星
问答堂专家综合评分
问题评分&:&3.3星
采纳、点赞&:&0星
二次回复率&:&0星
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
&&& 根据楼主描述的情况来看可能是手机系统造成的问题,建议楼主在备份手机数据之后尝试恢复手机的出厂设置,如果还是存在同样的情况的话,建议楼主联系手机厂商的售后服务进行检查或者系统升级,如果手机没有硬件故障的话问题应该就可以解决了。
留下你的评论
该内容由系统自动生成
参考价:¥860.00
主屏尺寸5英寸
电池容量2150mAh
主屏分辨率960x540像素
电池类型可拆卸式电池
后置摄像头500万像素
CPU频率1.2GHz
前置摄像头30万像素
CPU类型高通 骁龙Sna
网络类型双卡
名网友点评分数
入手三天,今天拍了几张,请大家评论器材:HUAWEI G610-T00时间: 16:47:49快门:1/152光圈:F/2.8焦距:3毫米感光度:124
微信公众账号ZOL问答堂
关注微信,随时随地解答您的疑惑
ZOL问答堂官方微博@ZOL问答堂
关注成功!该问题被回答后,将给您发送站内短信。
您也可以通过关注问答堂微信,及时获得您关注问题的回答。
微信关注问题方法“”家电百科 产品:
> 台灯是触摸开关,但有时候不触摸竟然会自动亮,这是为什么?
台灯是触摸开关,但有时候不触摸竟然会自动亮,这是为什么? 常见问题
触摸,当你触摸台灯的金属部分时,会产生一个感应信号,通过一级放大处理,给可控硅控制端一个开关信号,灯就亮了。如果你的台灯抗干扰能力差些,外界的干扰杂波通过你的台灯进入开关电路,产生误动作,台灯也会亮。解决办法:尝试在输入端与地之间接一个旁路电容,容量在几十皮法。或改变输入电路的抗干扰特性。
标签:&&&&&&&&&&&&&&&
" tab="tab_0" >常见问题热点事件家电人物家电名词热门品牌
热门新品123456789 123 4 5 6 7 8 9 10步步高s11t屏幕中间触摸不灵怎么办,步步高s11t版本更新后手机出现死机,开关机都不管用了。屏上出现rebootsystemnow是怎
来源:网络
关键字: 步步高s11t
更新时间:
延伸:本文除了聚合《步步高s11t屏幕中间触摸不灵怎么办》,免费提供的有关步步高s11t和步步高s11t版本更新后手机出现死机,开关机都不管用了。屏上出现rebootsystemnow是怎的内容之一,已有不少的网友认为此答案对自己有帮助!获取更多与《》相关的知识。
网友0的回答
您好!   1.长按电源键10秒强制重启手机试试。 2.您可以尝试充电20分钟再长按电源键10秒试一网友1的回答
步步高vivos11t,没有触屏校准这项设置,手机重启会自动校准。S11t搭载了一颗主频为1GHz的网友2的回答
可以上百脑汇看看 有专门修手机的 好像有两个屏把 里面的屏没坏 修就花不了多少钱网友1的回答
步步高vivo s11t新机子在出厂的时候带的那个薄膜并不是真正意义上的贴膜,只是一个PE薄膜,主要网友0的回答
先双击变成活动的图标格式(就是右上角带x的),然后把你想移动的拖动到最下面,(最下面没有位置的话,先网友1的回答
您可带着您的手机去售后服务中心更换主板,售后会有相关人员为您处理您手机的问题,售后服务中心执行的是全网友2的回答
步步高手机怎么出现这样的问题 秘密花园这个之前我也遇到过 后来是用手机急救箱全部清理了试试吧网友1的回答
上市日期:2013年手机类型:3G手机,智能手机外观设计:直板主屏尺寸:4.3英寸触摸屏:电容屏,多网友0的回答
最满意的回答
猜你感兴趣
回答问题赢iPhone 6Android SwitchButton(滑动开关)
版本:1.0日期: 版权:& 2014 kince 转载注明出处
在介绍SwitchButton之前,先来看一下系统Button是如何实现的。如下:@RemoteView
public class Button extends TextView {
public Button(Context context) {
this(context, null);
public Button(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.buttonStyle);
public Button(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(Button. class.getName());
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(Button. class.getName());
是直接继承于TextView,所不同的是在构造方法中添加了Button的样式,并且在初始化可见性方面交由Button类自己来处理。虽然Button的实现比较简单,但是它的子类并不是这样。看一下:
直接子类只有有一个,CompoundButton。它是一个抽象类,而实现这个类的控件正是CheckBox, RadioButton, Switch, ToggleButton这四个,所以先重点说一下它。源码如下:
* A button with two states, checked and unchecked. When the button is pressed
* or clicked, the state changes automatically.
* XML attributes
* See {@link android.R.styleable#CompoundButton
* CompoundButton Attributes}, {@link android.R.styleable#Button Button
* Attributes}, {@link android.R.styleable#TextView TextView Attributes}, {@link
* android.R.styleable #View View Attributes}
public abstract class CompoundButton extends Button implements Checkable {
private boolean mC
private int mButtonR
private boolean mB
private Drawable mButtonD
private OnCheckedChangeListener mOnCheckedChangeL
private OnCheckedChangeListener mOnCheckedChangeWidgetL
private static final int[] CHECKED_STATE_SET = {
R.attr.state_checked
public CompoundButton(Context context) {
this(context, null);
public CompoundButton(Context context, AttributeSet attrs) {
this(context, attrs, 0);
public CompoundButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a =
context.obtainStyledAttributes(
attrs, com.android.internal.poundButton, defStyle, 0);
Drawable d = a.getDrawable(com.android.internal.poundButton_button);
if (d != null ) {
setButtonDrawable(d);
boolean checked = a
.getBoolean(com.android.internal.poundButton_checked, false);
setChecked(checked);
a.recycle();
public void toggle() {
setChecked(! mChecked);
public boolean performClick() {
* XXX: These are tiny, need some surrounding 'expanded touch area',
* which will need to be implemented in Button if we only override
* performClick()
/* When clicked, toggle the state */
return super .performClick();
@ViewDebug.ExportedProperty
public boolean isChecked() {
* Changes the checked state of this button.
* @param checked true to check the button, false to uncheck it
public void setChecked(boolean checked) {
if (mChecked != checked) {
mChecked =
refreshDrawableState();
notifyViewAccessibilityStateChangedIfNeeded(
AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED );
// Avoid infinite recursions if setChecked() is called from a listener
if (mBroadcasting ) {
mBroadcasting =
if (mOnCheckedChangeListener != null) {
mOnCheckedChangeListener.onCheckedChanged(this, mChecked);
if (mOnCheckedChangeWidgetListener != null) {
mOnCheckedChangeWidgetListener .onCheckedChanged(this, mChecked);
mBroadcasting =
* Register a callback to be invoked when the checked state of this button
* changes.
* @param listener the callback to call on checked state change
public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
mOnCheckedChangeListener =
* Register a callback to be invoked when the checked state of this button
* changes. This callback is used for internal purpose only.
* @param listener the callback to call on checked state change
void setOnCheckedChangeWidgetListener(OnCheckedChangeListener listener) {
mOnCheckedChangeWidgetListener =
* Interface definition for a callback to be invoked when the checked state
* of a compound button changed.
public static interface OnCheckedChangeListener {
* Called when the checked state of a compound button has changed.
* @param buttonView The compound button view whose state has changed.
* @param isChecked
The new checked state of buttonView.
void onCheckedChanged(CompoundButton buttonView, boolean isChecked);
* Set the background to a given Drawable, identified by its resource id.
* @param resid the resource id of the drawable to use as the background
public void setButtonDrawable(int resid) {
if (resid != 0 && resid == mButtonResource ) {
mButtonResource =
Drawable d =
if (mButtonResource != 0) {
d = getResources().getDrawable(mButtonResource );
setButtonDrawable(d);
* Set the background to a given Drawable
* @param d The Drawable to use as the background
public void setButtonDrawable(Drawable d) {
if (d != null ) {
if (mButtonDrawable != null) {
mButtonDrawable.setCallback(null);
unscheduleDrawable( mButtonDrawable);
d.setCallback( this);
d.setVisible(getVisibility() == VISIBLE, false);
mButtonDrawable =
setMinHeight(mButtonDrawable .getIntrinsicHeight());
refreshDrawableState();
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(CompoundButton.class .getName());
event.setChecked( mChecked);
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(CompoundButton.class .getName());
info.setCheckable( true);
info.setChecked( mChecked);
public int getCompoundPaddingLeft() {
int padding = super.getCompoundPaddingLeft();
if (!isLayoutRtl()) {
final Drawable buttonDrawable = mButtonD
if (buttonDrawable != null) {
padding += buttonDrawable.getIntrinsicWidth();
public int getCompoundPaddingRight() {
int padding = super.getCompoundPaddingRight();
if (isLayoutRtl()) {
final Drawable buttonDrawable = mButtonD
if (buttonDrawable != null) {
padding += buttonDrawable.getIntrinsicWidth();
public int getHorizontalOffsetForDrawables() {
final Drawable buttonDrawable = mButtonD
return (buttonDrawable != null) ? buttonDrawable.getIntrinsicWidth() : 0;
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final Drawable buttonDrawable = mButtonD
if (buttonDrawable != null) {
final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK ;
final int drawableHeight = buttonDrawable.getIntrinsicHeight();
final int drawableWidth = buttonDrawable.getIntrinsicWidth();
int top = 0;
switch (verticalGravity) {
case Gravity.BOTTOM :
top = getHeight() - drawableH
case Gravity.CENTER_VERTICAL :
top = (getHeight() - drawableHeight) / 2;
int bottom = top + drawableH
int left = isLayoutRtl() ? getWidth() - drawableWidth : 0;
int right = isLayoutRtl() ? getWidth() : drawableW
buttonDrawable.setBounds(left, top, right, bottom);
buttonDrawable.draw(canvas);
protected int[] onCreateDrawableState(int extraSpace) {
final int [] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
return drawableS
protected void drawableStateChanged() {
super.drawableStateChanged();
if (mButtonDrawable != null) {
int[] myDrawableState = getDrawableState();
// Set the state of the Drawable
mButtonDrawable.setState(myDrawableState);
invalidate();
protected boolean verifyDrawable(Drawable who) {
return super .verifyDrawable(who) || who == mButtonD
public void jumpDrawablesToCurrentState() {
super.jumpDrawablesToCurrentState();
if (mButtonDrawable != null) mButtonDrawable.jumpToCurrentState();
static class SavedState extends BaseSavedState {
* Constructor called from {@link CompoundButton#onSaveInstanceState()}
SavedState(Parcelable superState) {
super(superState);
* Constructor called from {@link #CREATOR}
private SavedState(Parcel in) {
super(in);
checked = (Boolean)in.readValue( null);
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeValue( checked);
public String toString() {
return "CompoundButton.SavedState{"
+ Integer.toHexString(System.identityHashCode(this))
+ " checked=" + checked + "}" ;
public static final Parcelable.Creator CREATOR
= new Parcelable.Creator() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
public SavedState[] newArray(int size) {
return new SavedState[size];
public Parcelable onSaveInstanceState() {
// Force our ancestor class to save its state
setFreezesText( true);
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
ss. checked = isChecked();
public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState)
super.onRestoreInstanceState(ss.getSuperState());
setChecked(ss. checked);
requestLayout();
先从构造方法开始,在构造方法中, public CompoundButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a =
context.obtainStyledAttributes(
attrs, com.android.internal.poundButton, defStyle, 0);
Drawable d = a.getDrawable(com.android.internal.poundButton_button);
if (d != null ) {
setButtonDrawable(d);
boolean checked = a
.getBoolean(com.android.internal.poundButton_checked, false);
setChecked(checked);
a.recycle();
先是从attrs中读取定义的属性,一个是Drawable用于设置背景;一个是布尔类型变量用于判断是否check过。设置背景使用的是setButtonDrawable()方法,代码如下:/**
* Set the background to a given Drawable
* @param d The Drawable to use as the background
public void setButtonDrawable(Drawable d) {
if (d != null ) {
if (mButtonDrawable != null) {
mButtonDrawable.setCallback(null);
unscheduleDrawable( mButtonDrawable);
d.setCallback( this);
d.setVisible(getVisibility() == VISIBLE, false);
mButtonDrawable =
setMinHeight(mButtonDrawable .getIntrinsicHeight());
refreshDrawableState();
这个方法写的就比较完善,可以作为一个学习的典范。首先判断传递过来的Drawable是否为空,如果不为空并且默认的Drawable也不为空,那么取消默认Drawable的callback,然后调用unscheduleDrawable方法。这个方法代码如下: /**
* Unschedule any events associated with the given Drawable.
This can be
* used when selecting a new Drawable into a view, so that the previous
* one is completely unscheduled.
* @param who The Drawable to unschedule.
* @see #drawableStateChanged
public void unscheduleDrawable(Drawable who) {
if (mAttachInfo != null && who != null) {
mAttachInfo.mViewRootImpl .mChoreographer.removeCallbacks(
Choreographer.CALLBACK_ANIMATION, null, who);
从方法注释中可以看出它的用途,正是更换Drawable时候使用的。接下来开始重新设置Drawable,包括回调、可见性、最小高度。最后调用refreshDrawableState()方法,这个是View类的方法,用于更新Drawable状态。
然后再回过头看一下setChecked(checked)方法,这个用于设置check,也就是button的点击状态。代码如下:/**
* Changes the checked state of this button.
* @param checked true to check the button, false to uncheck it
public void setChecked( boolean checked) {
if (mChecked != checked) {
mChecked =
refreshDrawableState();
notifyViewAccessibilityStateChangedIfNeeded(
AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED );
// Avoid infinite recursions if setChecked() is called from a listener
if (mBroadcasting ) {
mBroadcasting =
if (mOnCheckedChangeListener != null) {
mOnCheckedChangeListener.onCheckedChanged(this, mChecked);
if (mOnCheckedChangeWidgetListener != null) {
mOnCheckedChangeWidgetListener .onCheckedChanged(this, mChecked);
mBroadcasting =
在这个方法中多出了一个接口,这个接口真是check的一个回调接口,代码如下:/**
* Interface definition for a callback to be invoked when the checked state
* of a compound button changed.
public static interface OnCheckedChangeListener {
* Called when the checked state of a compound button has changed.
* @param buttonView The compound button view whose state has changed.
* @param isChecked
The new checked state of buttonView.
void onCheckedChanged(CompoundButton buttonView, boolean isChecked);
这种回调接口在中处处可见,之前的文章也有介绍过。但是在上面的方法,它使用了一个mBroadcasting变量,进而巧妙地避免了重复递归的问题,大家自己感受一下。
然后就是ondraw()方法了,把之前的drawable画出来。代码如下:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final Drawable buttonDrawable = mButtonD
if (buttonDrawable != null) {
final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK ;
final int drawableHeight = buttonDrawable.getIntrinsicHeight();
final int drawableWidth = buttonDrawable.getIntrinsicWidth();
int top = 0;
switch (verticalGravity) {
case Gravity.BOTTOM :
top = getHeight() - drawableH
case Gravity.CENTER_VERTICAL :
top = (getHeight() - drawableHeight) / 2;
int bottom = top + drawableH
int left = isLayoutRtl() ? getWidth() - drawableWidth : 0;
int right = isLayoutRtl() ? getWidth() : drawableW
buttonDrawable.setBounds(left, top, right, bottom);
buttonDrawable.draw(canvas);
看得出来,在onDrawable()方法中,最主要的部分还是如何确定上下左右四个参数。确定完后就可以画出来了。但是,CompoundButton是一个抽象类,并不能直接使用,那看一下它的子类是如何实现的:1、CheckBox public class CheckBox extends CompoundButton {
public CheckBox(Context context) {
this(context, null);
public CheckBox(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.checkboxStyle);
public CheckBox(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(CheckBox. class.getName());
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(CheckBox. class.getName());
和Button的实现差不多,使用了一个自己的样式。并且也是重写了那两个方法。再来看一下RadioButton,public class RadioButton extends CompoundButton {
public RadioButton(Context context) {
this(context, null);
public RadioButton(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.radioButtonStyle);
public RadioButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
* {@inheritDoc}
* If the radio button is already checked, this method will not toggle the radio button.
public void toggle() {
// we override to prevent toggle when the radio is already
// checked (as opposed to check boxes widgets)
if (!isChecked()) {
super.toggle();
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(RadioButton. class.getName());
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(RadioButton. class.getName());
和CheckBox实现差不多,区别在于多重写了一个方法,用于防止按钮被重复点击。另外还有ToggleButton以及Switch,前者实现也比较简单,后者稍微麻烦了一些,感兴趣可以自己分析。
最后切入正题,看看滑动Button要如何实现呢?首先看一下效果图: 图1-1
图1-1所示的滑动Button实现的思路是这样的,背景图片有开和关的文字,一个按钮在其上面左右滑动,遮住相应的部分,使其在一个位置时候只能看到一个开关。
如图1-3,在实现的时候,先画一个开关背景图片只,然后在其上面画一个按钮,滑动开关的时候对上面的按钮进行处理即可。
1、按钮图片
2、背景图片
在自定义滑动按钮控件的时候,可以有多种选择,可以继承于Button,也可以继承于Button的子类,也可以继承于View类等。我们知道滑动按钮是一个很简单的控件,就是左右滑动改变显示内容,不需要其他的额外东西在里面,所以直接继承于View来实现即可。如果继承于系统的一些控件,那么有很多东西用不到,会造成浪费。
1、定义一个类继承于View,初始化构造方法,在构造方法中加载图片及其信息。
2、重写onMeasure()方法,计算控件的大小。
3、重写onTouchEvent()方法,对滑动事件进行判别处理。
4、定义接口,实现回调。
5、重写onDraw()方法,动态画出按钮。代码如下:/**
package com.kince.
import android.content.C
import android.graphics.B
import android.graphics.BitmapF
import android.graphics.C
import android.util.AttributeS
import android.util.L
import android.view.MotionE
import android.view.V
* @author kince
* @category 左右手势滑动button
* @serial 1.0.0
* @see http://blog.csdn.net/wangjinyu501
public class SlideButton extends View {
private Bitmap slideBitM// 滑动图片
private Bitmap switchBitM// 背景图片
private int slideBitMapW// 滑动图片宽度
private int switchBitMapW// 背景图片宽度
private int switchBitMapH// 背景图片高度
private boolean currentS// 开关状态
private boolean isSliding = // 是否正在滑动中
private int currentX; // 当前开关的位置
private OnToggleStateChangedListener mChangedL// 回调接口
* @param context
在java代码中直接调用使用此构造方法
public SlideButton(Context context) {
this(context, null);
// TODO Auto-generated constructor stub
* @param context
* @param attrs
在xml中使用要用到这个方法
public SlideButton(Context context, AttributeSet attrs) {
this(context, attrs, 0);
// TODO Auto-generated constructor stub
* @param context
* @param attrs
* @param defStyleAttr
指定一个样式
public SlideButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initBitmap();
* @category 加载背景图片以及开关图片 然后获取各自的宽高
private void initBitmap() {
// TODO Auto-generated method stub
slideBitMap = BitmapFactory.decodeResource(getResources(),
R.drawable.slide_button_background);
switchBitMap = BitmapFactory.decodeResource(getResources(),
R.drawable.switch_background);
slideBitMapWidth = slideBitMap.getWidth();
switchBitMapWidth = switchBitMap.getWidth();
switchBitMapHeight = switchBitMap.getHeight();
Log.i("switchBitMapWidth", switchBitMapWidth + "");
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(switchBitMapWidth, switchBitMapHeight);// 设置控件的宽高
protected void onDraw(Canvas canvas) {
// 绘制button背景图片
canvas.drawBitmap(switchBitMap, 0, 0, null);
// 绘制滑动开关
if (isSliding) {// 如果当前状态是滑动中 则动态绘制开关
int dis = currentX - slideBitMapWidth / 2;
switchBitMapWidth - slideBitMapWidth) {
dis = switchBitMapWidth - slideBitMapW
canvas.drawBitmap(slideBitMap, dis, 0, null);
if (currentState) { // 绘制开关为开的状态
canvas.drawBitmap(slideBitMap, switchBitMapWidth
- slideBitMapWidth, 0, null);
} else { // 绘制开关为关的状态
canvas.drawBitmap(slideBitMap, 0, 0, null);
super.onDraw(canvas);
public boolean onTouchEvent(MotionEvent event) {
// 手势识别 判断滑动方向
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
isSliding =
currentX = (int) event.getX();
case MotionEvent.ACTION_MOVE:
currentX = (int) event.getX();
Log.i("currentX", currentX + "");
case MotionEvent.ACTION_UP:
isSliding =
int bgCenter = switchBitMapWidth / 2;
boolean state = currentX > bgC // 改变后的状态
if (state != currentState && mChangedListener != null) {// 添加回调
mChangedListener.onToggleStateChanged(state);
currentState =
invalidate();
public OnToggleStateChangedListener getmChangedListener() {
return mChangedL
public void setmChangedListener(
OnToggleStateChangedListener mChangedListener) {
this.mChangedListener = mChangedL
public boolean isToggleState() {
return currentS
public void setToggleState(boolean currentState) {
this.currentState = currentS
回调接口,
package com.kince.
* @author kince
public interface OnToggleStateChangedListener {
* @category
* @param state
public void onToggleStateChanged(boolean state);
Activity代码,package com.kince.
import android.support.v7.app.ActionBarA
import android.support.v7.app.ActionB
import android.support.v4.app.F
import android.support.v4.app.FragmentA
import android.os.B
import android.view.LayoutI
import android.view.M
import android.view.MenuI
import android.view.V
import android.view.ViewG
import android.widget.T
import android.os.B
public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
public boolean onCreateOptionsMenu(Menu menu) {
// I this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return super.onOptionsItemSelected(item);
* A placeholder fragment containing a simple view.
public static class PlaceholderFragment extends Fragment implements
OnToggleStateChangedListener {
private SlideB
public PlaceholderFragment() {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
slidebutton = (SlideButton) rootView.findViewById(R.id.slidebutton1);
// 设置一下开关的状态
slidebutton.setToggleState(true); // 设置开关的状态为打开
slidebutton.setmChangedListener(this);
return rootV
public void onToggleStateChanged(boolean state) {
// TODO Auto-generated method stub
FragmentActivity activity = getActivity();
if (state) {
Toast.makeText(activity, "开关打开", 0).show();
Toast.makeText(activity, "开关关闭", 0).show();
未完待续。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'}

我要回帖

更多关于 bootstrap 滑动开关 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信