本文整理汇总了Java中android.widget.Switch类的典型用法代码示例。如果您正苦于以下问题:Java Switch类的具体用法?Java Switch怎么用?Java Switch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Switch类属于android.widget包,在下文中一共展示了Switch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.Switch; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.text);
updateText();
Switch s = findViewById(R.id.switch_widget);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
RedirectStorage.enable(new PathCallback() {
@Override
public File onModify(File original) {
return getFilesDir();
}
});
} else {
RedirectStorage.disable();
}
updateText();
}
});
}
示例2: onSwitchChanged
import android.widget.Switch; //导入依赖的package包/类
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
if (DEBUG) Log.d(TAG, "onSwitchChanged " + isChecked);
if (mDisableListeners) return;
final boolean enabled = isChecked;
if (enabled == mRule.enabled) return;
MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ENABLE_RULE, enabled);
if (DEBUG) Log.d(TAG, "onSwitchChanged enabled=" + enabled);
mRule.enabled = enabled;
mRule.snoozing = false;
setZenModeConfig(mConfig);
if (enabled) {
final int toastText = getEnabledToastText();
if (toastText != 0) {
mEnabledToast = Toast.makeText(mContext, toastText, Toast.LENGTH_SHORT);
mEnabledToast.show();
}
} else {
if (mEnabledToast != null) {
mEnabledToast.cancel();
}
}
}
示例3: initView
import android.widget.Switch; //导入依赖的package包/类
private void initView(Context context) {
rootView = View.inflate(context, R.layout.widget_ver_controller, this);
ivBack = (ImageView) findViewById(R.id.iv_thelive_back);
verMediaControll = findViewById(R.id.verMediaControll);
infoContainer = findViewById(R.id.infoContainer);
ll_four_container = (LinearLayout) findViewById(R.id.ll_four_container);
theliveMore = (ImageView) findViewById(R.id.iv_thelive_more);
check_gift_switch = (CheckBox) findViewById(R.id.check_gift_switch);
check_live_pause = (CheckBox) findViewById(R.id.check_live_pause);
ivFullscreen = (ImageView) findViewById(R.id.iv_thelive_fullscreen);
theliveNum = (TextView) findViewById(R.id.tv_thelive_num);
ll_jubao_and_share = (LinearLayout) findViewById(R.id.ll_jubao_and_share);
tv_jubao = (TextView) findViewById(R.id.tv_jubao);
tv_share = (TextView) findViewById(R.id.tv_share);
live_vertical_bottom = (FrameLayout) findViewById(R.id.live_vertical_bottom);
//info
ic_head = (ImageView) findViewById(R.id.ic_head);
nickName = (TextView) findViewById(R.id.nickName);
titleName = (TextView) findViewById(R.id.title);
ivIsFocus = (ImageView) findViewById(R.id.iv_thelive_focus);
swRemind = (Switch) findViewById(R.id.switchview_remind);
}
示例4: onCreateView
import android.widget.Switch; //导入依赖的package包/类
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.debug_drawer_mock_ble, parent, false);
Switch mockBle = view.findViewById(R.id.debug_drawer_ble_mock);
mockBle.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
mainActivity.provideBluetoothUtil(new BluetoothUtilMockImpl());
} else {
mainActivity.provideBluetoothUtil(new BluetoothUtilImpl());
}
});
return view;
}
示例5: _initialize
import android.widget.Switch; //导入依赖的package包/类
@Hide
@Override
public void _initialize(final BA ba, Object activityClass, String EventName) {
final Switch _switch = new Switch(ba.context);
final String eventName = EventName.toLowerCase(BA.cul);
setObject(_switch);
innerInitialize(ba, eventName, true);
if (ba.subExists(eventName + "_checkedchange")) {
getObject().setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
ba.raiseEventFromUI(_switch,eventName + "_checkedchange", isChecked);
}
});
}
}
示例6: onFinishInflate
import android.widget.Switch; //导入依赖的package包/类
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mIconView = (ImageView) findViewById(R.id.icon);
mMountSwitch = (Switch) findViewById(R.id.mount_switch);
mLabelView = (TextView) findViewById(R.id.label);
mVersionView = (TextView) findViewById(R.id.version);
mRunView = (TextView) findViewById(R.id.run);
mInfoView = (TextView) findViewById(R.id.info);
mAddToLauncherView = (TextView) findViewById(R.id.add_to_launcher);
mMountSwitch.setOnCheckedChangeListener(this);
mRunView.setOnClickListener(this);
mInfoView.setOnClickListener(this);
mAddToLauncherView.setOnClickListener(this);
}
示例7: SwitchItem
import android.widget.Switch; //导入依赖的package包/类
public SwitchItem(Context context, String title, String key, boolean defaultValue) {
super(context);
this.mKey = key;
this.mDefaultValue = defaultValue;
View.inflate(getContext(), R.layout.view_switch_item, this);
TextView titleView = (TextView) findViewById(R.id.title);
titleView.setText(title);
mSwitchView = (Switch) findViewById(R.id.switcher);
mSwitchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
SharedPreferences.Editor editor = App.sp.edit();
editor.putBoolean(key, isChecked);
editor.apply();
});
}
示例8: referenceViews
import android.widget.Switch; //导入依赖的package包/类
private void referenceViews() {
switchNotifications = (Switch) findViewById(R.id.switchNotifications);
switchNotificationSound = (Switch) findViewById(R.id.switchNotificationSound);
switchNotificationLight = (Switch) findViewById(R.id.switchNotificationLight);
switchNotificationVibrations = (Switch) findViewById(R.id.switchNotificationVibrations);
textViewNotificationPeriod = (TextView) findViewById(R.id.textViewNotificationPeriod);
String notification = getResources().getString(R.string.notification);
String notificationSub = getResources().getString(R.string.notification_sub_2);
Span.span(notification, notificationSub, switchNotifications);
String notificationSound = getResources().getString(R.string.notification_sound);
Span.span(notificationSound, switchNotificationSound);
String notificationLight = getResources().getString(R.string.notification_light);
Span.span(notificationLight, switchNotificationLight);
String notificationVibration = getResources().getString(R.string.notification_vibration);
Span.span(notificationVibration, switchNotificationVibrations);
String notificationPeriod = getResources().getString(R.string.notification_period);
String notificationPeriodSub = getResources().getString(R.string.notification_period_sub);
Span.span(notificationPeriod, notificationPeriodSub, textViewNotificationPeriod);
}
示例9: referenceViews
import android.widget.Switch; //导入依赖的package包/类
private void referenceViews() {
switchProfile = (Switch) findViewById(R.id.switchProfile);
switchGoogle = (Switch) findViewById(R.id.switchGoogle);
textViewNotifications = (TextView) findViewById(R.id.textViewNotifications);
switchCurrency = (Switch) findViewById(R.id.switchCurrency);
String profile = getResources().getString(R.string.profile);
String profileSub = getResources().getString(R.string.profile_sub);
Span.span(profile, profileSub, switchProfile);
String profileGoogle = getResources().getString(R.string.profile_google);
String profileGoogleSub = getResources().getString(R.string.profile_google_sub);
Span.span(profileGoogle, profileGoogleSub, switchGoogle);
String notification = getResources().getString(R.string.notification);
String notificationSub = getResources().getString(R.string.notification_sub);
Span.span(notification, notificationSub, textViewNotifications);
String currency = getResources().getString(R.string.currency);
String currencySub = getResources().getString(R.string.currency_sub);
Span.span(currency, currencySub, switchCurrency);
}
示例10: BlockingItemViewHolder
import android.widget.Switch; //导入依赖的package包/类
BlockingItemViewHolder(View itemView, final BrowserFragment fragment) {
super(itemView);
this.fragment = fragment;
final Switch switchView = itemView.findViewById(R.id.blocking_switch);
switchView.setChecked(fragment.getSession().isBlockingEnabled());
switchView.setOnCheckedChangeListener(this);
final View helpView = itemView.findViewById(R.id.help_trackers);
helpView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (browserFragment != null) {
browserFragment.onClick(view);
}
}
});
trackerCounter = itemView.findViewById(R.id.trackers_count);
updateTrackers(fragment.getSession().getBlockedTrackers().getValue());
}
示例11: onCreateOptionsMenu
import android.widget.Switch; //导入依赖的package包/类
/**
* Creates menu functionality.
* @param menu
* @return
*/
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu_nearby_events, menu);
final MenuItem nearbyToggle = menu.findItem(R.id.nearbyEventSwitch);
final Switch actionView = (Switch) nearbyToggle.getActionView().findViewById(R.id.mapSwitch);
actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){//Needs to call some method otherwise doesn't work
addNearbyMarkers(gmap);
}
else{
addAllMarkers(gmap);
}
}
});
return super.onCreateOptionsMenu(menu);
}
示例12: onCreate
import android.widget.Switch; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSwitch=(Switch)findViewById(R.id.switch1);
mSwitch.setChecked(checkSystemWritePermission());
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// 开启switch,设置提示信息
getPermission();
} else {
// 关闭swtich,设置提示信息
mSwitch.setText(getString(R.string.text_off));
}
}
});
}
示例13: initView
import android.widget.Switch; //导入依赖的package包/类
private void initView()
{
switch_voice= (Switch) findViewById(R.id.switch_voice);
switch_sms= (Switch) findViewById(R.id.switch_sms);
ll_check_version= (LinearLayout) findViewById(R.id.ll_check_version);
tv_version_name= (TextView) findViewById(R.id.tv_version_name);
ll_scan_qrcode= (LinearLayout) findViewById(R.id.ll_scan_qrcode);
ll_my_qrcode= (LinearLayout) findViewById(R.id.ll_my_qrcode);
ll_location= (LinearLayout) findViewById(R.id.ll_location);
//获取当前版本信息显示在界面上
showCurrentVersionInfo();
//为各种开关设置监听事件
switch_voice.setOnClickListener(this);
switch_sms.setOnClickListener(this);
ll_check_version.setOnClickListener(this);
ll_scan_qrcode.setOnClickListener(this);
ll_my_qrcode.setOnClickListener(this);
ll_location.setOnClickListener(this);
//进入界面后读取之前保存的开关状态
switch_voice.setChecked(SharedUtils.getBoolean("voice_key",false));
switch_sms.setChecked(SharedUtils.getBoolean("sms_key",false));
}
示例14: getView
import android.widget.Switch; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
InstalledApp app = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_app, parent, false);
}
// Lookup view for data population
appImage = (ImageView) convertView.findViewById(R.id.appImage);
appPackage = (Switch) convertView.findViewById(R.id.appSwitch);
appName = (TextView) convertView.findViewById(R.id.appName);
appImage.setImageDrawable(app.image);
appPackage.setText(app.packageName);
appName.setText(app.name);
// Return the completed view to render on screen
return convertView;
}
示例15: createSlaveView
import android.widget.Switch; //导入依赖的package包/类
@Override
public View createSlaveView() {
// TODO Auto-generated method stub
TVMenuItem slaveView;
if(findViewById(R.id.info_text)!=null && findViewById(R.id.info_text) instanceof RadioButton){
slaveView = (TVMenuItem)LayoutInflater.from(mContext)
.inflate(R.layout.menu_item_checkable_layout, null);
}
else if(findViewById(R.id.info_text)!=null && findViewById(R.id.info_text) instanceof Switch){
slaveView = (TVMenuItem)LayoutInflater.from(mContext)
.inflate(R.layout.menu_item_switchable_layout, null);
}
else{
slaveView = (TVMenuItem)(View)LayoutInflater.from(mContext)
.inflate(R.layout.menu_item_layout, null);
}
setSlaveView(slaveView);
return slaveView;
}