首页

SwitchButton开关按钮的多种实现方式

java

2020-7-16

package com.example.compoundbuttonview;

import com.example.compoundbuttonview.view.CheckSwitchButton;
import com.example.compoundbuttonview.view.SlideSwitchView;
import com.example.compoundbuttonview.view.SlideSwitchView.OnSwitchChangedListener;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
/**
 * @author RA
 * @blog http://blog.csdn.net/vipzjyno1
 */
public class MainActivity extends Activity {
	private ToggleButton mTogBtn;
	private CheckSwitchButton mCheckSwithcButton;
	private CheckSwitchButton mEnableCheckSwithcButton;
	private SlideSwitchView mSlideSwitchView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initView();
	}

	private void initView() {
		mTogBtn = (ToggleButton) findViewById(R.id.mTogBtn); // 获取到控件
		mTogBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					//选中
				}else{
					//未选中
				}
			}
		});// 添加监听事件
		mCheckSwithcButton = (CheckSwitchButton)findViewById(R.id.mCheckSwithcButton);
		mEnableCheckSwithcButton = (CheckSwitchButton)findViewById(R.id.mEnableCheckSwithcButton);
		mCheckSwithcButton.setChecked(false);
		mCheckSwithcButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					mEnableCheckSwithcButton.setEnabled(false);
					mSlideSwitchView.setEnabled(false);
				}else{
					mEnableCheckSwithcButton.setEnabled(true);
					mSlideSwitchView.setEnabled(true);
				}
			}
		});
		mSlideSwitchView = (SlideSwitchView) findViewById(R.id.mSlideSwitchView);
		mSlideSwitchView.setOnChangeListener(new OnSwitchChangedListener() {
			
			@Override
			public void onSwitchChange(SlideSwitchView switchView, boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					
				}
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

资源下载此资源下载价格为2D币(VIP免费),请先
资源文件列表
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/.classpath , 475
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/.project , 877
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/.settings/org.eclipse.jdt.core.prefs , 177
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/AndroidManifest.xml , 902
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/AndroidManifest.xml , 902
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes.dex , 732752
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/anim/FrameAnimationController$AnimationHandler.class , 1001
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/anim/FrameAnimationController.class , 1468
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/BuildConfig.class , 369
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/MainActivity$1.class , 913
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/MainActivity$2.class , 1415
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/MainActivity$3.class , 999
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/MainActivity.class , 2674
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$attr.class , 8265
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$color.class , 438
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$dimen.class , 497
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$drawable.class , 1152
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$id.class , 1795
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$layout.class , 430
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$menu.class , 424
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$string.class , 575
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$style.class , 497
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R$styleable.class , 1599
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/R.class , 921
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/CheckSwitchButton$1.class , 826
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/CheckSwitchButton$PerformClick.class , 953
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/CheckSwitchButton$SwitchAnimation.class , 1214
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/CheckSwitchButton.class , 9326
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/SlideSwitchView$OnSwitchChangedListener.class , 370
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/SlideSwitchView.class , 6056
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/classes/com/example/compoundbuttonview/view/SwitchButton.class , 14729
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/CompoundButtonView(自定义控件属性).apk , 352804
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/dexedLibs/android-support-v4-038de6267b609f8a9b5c636d6d8d12e5.jar , 234431
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/dexedLibs/android-support-v4-c5caaa6a987d7b8c5a9427be3f8f1ef2.jar , 234420
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/jarlist.cache , 120
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/resources.ap_ , 99992
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/checkbox_off.png , 2524
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/checkbox_on.png , 4144
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/ic_launcher.png , 5964
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/ios7_switch_off.png , 2243
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/ios7_switch_on.png , 4502
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/switch_btn_off.png , 1300
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/switch_btn_on.png , 1836
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/switch_btn_slipper.png , 2701
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/toggle_btn_checked.png , 928
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-hdpi/toggle_btn_unchecked.png , 759
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-mdpi/ic_launcher.png , 3112
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xhdpi/checkswitch_bottom.png , 2602
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xhdpi/checkswitch_btn_pressed.png , 3196
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xhdpi/checkswitch_btn_unpressed.png , 3307
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xhdpi/checkswitch_frame.png , 2797
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xhdpi/checkswitch_mask.png , 587
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xhdpi/ic_launcher.png , 9355
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/bin/res/drawable-xxhdpi/ic_launcher.png , 17889
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/gen/com/example/compoundbuttonview/BuildConfig.java , 172
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/gen/com/example/compoundbuttonview/R.java , 102496
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/ic_launcher-web.png , 51394
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/libs/android-support-v4.jar , 627582
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/proguard-project.txt , 781
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/project.properties , 563
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/checkbox_off.png , 2524
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/checkbox_on.png , 4144
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/ic_launcher.png , 7658
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/ios7_switch_off.png , 2243
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/ios7_switch_on.png , 4502
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/switch_btn_off.png , 1300
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/switch_btn_on.png , 1836
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/switch_btn_slipper.png , 2701
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/toggle_btn_checked.png , 928
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-hdpi/toggle_btn_unchecked.png , 759
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-mdpi/ic_launcher.png , 3777
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xhdpi/checkswitch_bottom.png , 5317
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xhdpi/checkswitch_btn_pressed.png , 3262
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xhdpi/checkswitch_btn_unpressed.png , 3373
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xhdpi/checkswitch_frame.png , 2864
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xhdpi/checkswitch_mask.png , 866
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xhdpi/ic_launcher.png , 12516
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable-xxhdpi/ic_launcher.png , 24777
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable/checkbox_iphone.xml , 523
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable/ios7_btn.xml , 271
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable/switch_btn.xml , 269
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/drawable/toggle_btn.xml , 280
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/layout/main.xml , 4011
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/menu/main.xml , 263
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values-sw600dp/dimens.xml , 203
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values-sw720dp-land/dimens.xml , 277
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values-v11/styles.xml , 334
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values-v14/styles.xml , 391
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values/attrs.xml , 12340
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values/dimens.xml , 220
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values/strings.xml , 235
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values/styles.xml , 697
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/res/values/style_switch.xml , 3498
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/src/com/example/compoundbuttonview/anim/FrameAnimationController.java , 1111
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/src/com/example/compoundbuttonview/MainActivity.java , 2603
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/src/com/example/compoundbuttonview/view/CheckSwitchButton.java , 11005
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/src/com/example/compoundbuttonview/view/SlideSwitchView.java , 7083
SwitchButton开关按钮的多种实现方式/CompoundButtonView(自定义控件属性)/src/com/example/compoundbuttonview/view/SwitchButton.java , 19168
没有账号? 忘记密码?

社交账号快速登录