本文整理汇总了Java中android.support.v7.widget.SwitchCompat.setChecked方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchCompat.setChecked方法的具体用法?Java SwitchCompat.setChecked怎么用?Java SwitchCompat.setChecked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.SwitchCompat
的用法示例。
在下文中一共展示了SwitchCompat.setChecked方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSharedPreferenceChanged
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
if ("log".equals(name)) {
// Get enabled
boolean log = prefs.getBoolean(name, false);
// Display disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != log)
swEnabled.setChecked(log);
ServiceSinkhole.reload("changed " + name, ActivityLog.this);
}
}
示例2: onCreateOptionsMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_switch, menu);
// Get the action view used in your toggleservice item
final MenuItem toggle = menu.findItem(R.id.menu_switch);
mSwitch = (SwitchCompat) toggle.getActionView().findViewById(R.id.switchInActionBar);
mSwitch.setEnabled(mTransportIdEditText.length() > 0 && mEmailEditText.length() > 0 &&
mPasswordEditText.length() > 0);
mSwitch.setChecked(mStartButton.getVisibility() != View.VISIBLE);
mSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((SwitchCompat) v).isChecked()) {
checkInputFields();
} else {
confirmStop();
}
}
});
return super.onCreateOptionsMenu(menu);
}
示例3: onActivityResult
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
SwitchCompat switchshutdowncountdown = (SwitchCompat) findViewById(R.id.switchshutdowncountdown);
if (requestCode == REQUEST_CODE) {
if (android.provider.Settings.canDrawOverlays(Settings_Activity.this)) {
// continue here - permission was granted
settingsprefs.edit().putBoolean("sysOverlay", true).apply();
switchshutdowncountdown.setChecked(true);
} else {
settingsprefs.edit().putBoolean("sysOverlay", false).apply();
switchshutdowncountdown.setChecked(false);
}
} else if (requestCode == REQUEST_CODE_ENABLE) {
settingsprefs.edit().putBoolean("pinprotection", true).apply();
changepin.setVisibility(View.VISIBLE);
changepindivider.setVisibility(View.VISIBLE);
}
}
示例4: onCreateOptionsMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
MenuItem menuItem = menu.findItem(R.id.menu_item_switch);
if (menuItem == null) {
return false;
}
switchProxy = (SwitchCompat) menuItem.getActionView();
if (switchProxy == null) {
return false;
}
switchProxy.setChecked(LocalVpnService.IsRunning);
switchProxy.setOnCheckedChangeListener(this);
return true;
}
示例5: onCreateOptionsMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// We need to inflate the menu for the app bar, to display the switch
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.vibration_activity_menu, menu);
final MenuItem item = menu.findItem(R.id.vibration_switch);
SwitchCompat mainSwitch = (SwitchCompat) item.getActionView();
mainSwitch.setOnCheckedChangeListener
(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged
(CompoundButton buttonView, boolean isChecked) {
settingsModel.setVibrationServiceOn(isChecked);
}
});
// Initialise the switch to the current vibrate service state.
mainSwitch.setChecked(settingsModel.isVibrationServiceOn());
VibrationAlarmScheduler.updateAlarms(this);
return true;
}
示例6: setChannel
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void setChannel(String subscribeType, Subscription subscription, SwitchCompat email, SwitchCompat push, SwitchCompat sms) {
if (subscribeType.equalsIgnoreCase(subscription.getType())) {
for (Channel channel : subscription.getChannels()) {
if (Channel.CHANNEL_EMAIL.equalsIgnoreCase(channel.getName())) {
if (email != null) {
email.setChecked(channel.isEnabled());
}
} else if (Channel.CHANNEL_PUSH.equalsIgnoreCase(channel.getName())) {
if (push != null) {
push.setChecked(channel.isEnabled());
}
} else if (Channel.CHANNEL_SMS.equalsIgnoreCase(channel.getName())) {
if (sms != null) {
sms.setChecked(channel.isEnabled());
}
}
}
}
}
示例7: onCreateView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (rootView == null) {
rootView = inflater.inflate(R.layout.fragment_settings, container, false);
//switchCompatStatus = (SwitchCompat) rootView.findViewById(R.id.switch_status);
// switchCompatResponse = (SwitchCompat) rootView.findViewById(R.id.switch_response);
// switchCompatCreated = (SwitchCompat) rootView.findViewById(R.id.switch_created);
// switchCompatAssignedGroup = (SwitchCompat) rootView.findViewById(R.id.switch_assigned_group);
// switchCompatAssignedMe = (SwitchCompat) rootView.findViewById(R.id.switch_assigned_me);
switchCompatCrashReports = (SwitchCompat) rootView.findViewById(R.id.switch_crash_reports);
switchCompatCrashReports.setChecked(Preference.isCrashReport());
// switchCompatCrashReports.setOnCheckedChangeListener(this);
switchCompatCrashReports.setOnClickListener(this);
}
((MainActivity) getActivity()).setActionBarTitle("Settings");
return rootView;
}
示例8: initNavView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void initNavView(){
MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme);
mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
mThemeSwitch = (SwitchCompat) MenuItemCompat
.getActionView(item)
.findViewById(R.id.theme_switch);
//
mThemeSwitch.setChecked(!SkinPreUtils.getInstance(this).getSkinPath().equals(""));
mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
/*
* 这里有待改进,是读取apk包的地方
* */
String skinPath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator
+ "skin_night.apk";
mSkinManager.loadSkin(skinPath);
}else{
mSkinManager.restoreDefault();
}
}
});
}
示例9: onCreateDialog
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View root = View.inflate(getActivity(), R.layout.dialog_dialog_options, null);
scEnable = (SwitchCompat) root.findViewById(R.id.enable);
scHighPriority = (SwitchCompat) root.findViewById(R.id.priority);
scSound = (SwitchCompat) root.findViewById(R.id.sound);
scVibro = (SwitchCompat) root.findViewById(R.id.vibro);
scLed = (SwitchCompat) root.findViewById(R.id.led);
scEnable.setChecked(hasFlag(mask, FLAG_SHOW_NOTIF));
scEnable.setOnCheckedChangeListener((buttonView, isChecked) -> resolveOtherSwitches());
scSound.setChecked(hasFlag(mask, FLAG_SOUND));
scHighPriority.setChecked(hasFlag(mask, FLAG_HIGH_PRIORITY));
scVibro.setChecked(hasFlag(mask, FLAG_VIBRO));
scLed.setChecked(hasFlag(mask, FLAG_LED));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.peer_notification_settings)
.setPositiveButton(R.string.button_ok, (dialog, whichButton) -> onSaveClick())
.setNeutralButton(R.string.set_default, (dialog, which) -> Settings.get()
.notifications()
.setDefault(accountId, peerId));
builder.setView(root);
resolveOtherSwitches();
return builder.create();
}
示例10: setLocationPreference
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void setLocationPreference(boolean on, String prefKey, SwitchCompat check, final int requestCode) {
if(on) {
if(ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
settings.edit().putInt(prefKey, 1).apply();
updateValues();
} else {
if(getActivity() != null && !getActivity().isFinishing()) {
if(ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {
check.setChecked(false); // Wait for result until switch is set
Snackbar.make(coordinator, R.string.settings_general_location_permission_rationale, Snackbar.LENGTH_LONG)
.setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestCode);
}
}).show();
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestCode);
}
}
}
} else {
settings.edit().putInt(prefKey, 0).apply();
updateValues();
}
}
示例11: onTitleSubtitleSwitchClick
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onTitleSubtitleSwitchClick(View view, final TitleSubtitleSwitchData data, final int position) {
boolean oldValue = data.isSwitchOn();
final boolean newValue = !oldValue;
SwitchCompat switchCompat = view.findViewById(R.id.switchView);
data.setSwitchOn(newValue);
switchCompat.setChecked(newValue);
}
示例12: onBindView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
protected void onBindView(View view) {
super.onBindView(view);
if (mDrawDivider) {
int left = view.getPaddingLeft();
int right = view.getPaddingRight();
int top = view.getPaddingTop();
int bottom = view.getPaddingBottom();
view.setBackground(DividerDrawable.create(getContext()));
view.setPadding(left, top, right, bottom);
}
SwitchCompat switchView = (SwitchCompat) view.findViewById(R.id.switch_widget);
// On BLU Life Play devices SwitchPreference.setWidgetLayoutResource() does nothing. As a
// result, the user will see a non-material Switch and switchView will be null, hence the
// null check below. http://crbug.com/451447
if (switchView != null) {
switchView.setChecked(isChecked());
}
TextView title = (TextView) view.findViewById(android.R.id.title);
title.setSingleLine(false);
if (!mDontUseSummaryAsTitle && TextUtils.isEmpty(getTitle())) {
TextView summary = (TextView) view.findViewById(android.R.id.summary);
title.setText(summary.getText());
title.setVisibility(View.VISIBLE);
summary.setVisibility(View.GONE);
}
if (mManagedPrefDelegate != null) mManagedPrefDelegate.onBindViewToPreference(this, view);
}
示例13: onSharedPreferenceChanged
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
if ("enabled".equals(name)) {
// Get enabled
boolean enabled = prefs.getBoolean(name, false);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != enabled)
swEnabled.setChecked(enabled);
}
}
示例14: getOfflineSwitcher
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
public SwitchCompat getOfflineSwitcher() {
SwitchCompat offlineModeSwitch = (SwitchCompat) getNavigationView().getMenu().findItem(R.id.nav_mode_switch).getActionView().findViewById(R.id.menu_switch);
if (!preferenceUtils.checkPreference(PreferenceUtils.OFFLINE_MODE)) {
preferenceUtils.writeLogic(PreferenceUtils.OFFLINE_MODE, false);
} else {
offlineModeSwitch.setChecked(preferenceUtils.readLogic(PreferenceUtils.OFFLINE_MODE));
}
return offlineModeSwitch;
}
示例15: onReceive
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
// Extract data included in the Intent
String message = intent.getStringExtra("message");
String payloadData = intent.getStringExtra("payload");
String topic = intent.getStringExtra("topic");
Log.d(TAG, "Got message: " + message);
switch (message) {
case "rxmessage":
addLastMeasurementToMap();
break;
case "locationupdate":
autoCenterMap();
break;
case "selfstop":
Log.d(TAG, "Received selfstop from service.");
stopLoggingService();
SwitchCompat toggleButton = (SwitchCompat) findViewById(R.id.switchStartLogging);
toggleButton.setChecked(false);
if (payloadData == null) {
setStatusMessage("Mapping stopped unexpectedly");
} else {
setStatusMessage("Mapping stopped - " + payloadData);
}
break;
case "notification":
setStatusMessage(payloadData);
break;
case "test":
Log.d(TAG, "Test message received");
break;
default:
Log.d(TAG, "Unknown message received");
}
}