本文整理汇总了Java中android.support.v7.widget.SwitchCompat.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchCompat.setEnabled方法的具体用法?Java SwitchCompat.setEnabled怎么用?Java SwitchCompat.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.SwitchCompat
的用法示例。
在下文中一共展示了SwitchCompat.setEnabled方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: prepareMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void prepareMenu(Menu m) {
if(m != null) {
SwitchCompat switchh = (SwitchCompat) ((MenuItemImpl) m.findItem(R.id.menu_item_switch)).getActionView().findViewById(R.id.pluginEnabledSwitch);
if(isKeepassInstalled()) {
switchh.setEnabled(true);
switchh.setChecked(isEnabled());
switchh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
enableDisablePlugin();
}
});
} else
switchh.setChecked(false);
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
m.findItem(R.id.menuVersion).setTitle("v:" + version);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
}
示例3: onServiceConnected
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
Log.d(TAG, "onServiceConected");
// We've bound to LocalService, cast the IBinder and get LocalService instance
TTNMapperService.LocalBinder binder = (TTNMapperService.LocalBinder) service;
mService = binder.getService();
mBound = true;
//disable toggle button until service is bound
SwitchCompat toggleButton = (SwitchCompat) findViewById(R.id.switchStartLogging);
toggleButton.setEnabled(true);
}
示例4: onServiceDisconnected
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onServiceDisconnected(ComponentName arg0) {
Log.d(TAG, "onServiceDisconnected");
mBound = false;
//disable toggle button until service is bound
SwitchCompat toggleButton = (SwitchCompat) findViewById(R.id.switchStartLogging);
toggleButton.setEnabled(true);
}
示例5: onCreateOptionsMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
MenuItem item = menu.findItem(R.id.action_switch);
if (item != null) {
SwitchCompat action_bar_switch = (SwitchCompat) item.getActionView().findViewById(R.id.action_switch);
if (action_bar_switch != null) {
if (hasAccessGranted()) {
action_bar_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(Utils.PREF_ENABLED, isChecked).apply();
refreshState();
}
});
if (mPreferences.getBoolean(Utils.PREF_ENABLED, false)) {
action_bar_switch.setChecked(true);
} else {
action_bar_switch.setChecked(false);
}
action_bar_switch.setEnabled(true);
} else {
action_bar_switch.setChecked(false);
action_bar_switch.setEnabled(false);
}
}
}
return true;
}
示例6: addItemPrefWithToggle
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
public ItemBuilder addItemPrefWithToggle(Context context, String title, String subtitle, boolean isChecked, boolean useSwitch, boolean isProFeature, boolean userIsPro, String preferenceCONST, String settingsEnabledAction, String settingsDisabledAction) {
view = inflater.inflate(R.layout.item_element_title_subtitle_checkbox, parent, false);
TextView tv = (TextView) view.findViewById(R.id.tv_title);
tv.setText(title);
TextView tv2 = (TextView) view.findViewById(R.id.tv_subtitle);
tv2.setText(subtitle);
CheckBox checkboxButton = (CheckBox) view.findViewById(R.id.cb_pref);
SwitchCompat switchButton = (SwitchCompat) view.findViewById(R.id.sw_pref);
checkboxButton.setChecked(isChecked);
switchButton.setChecked(isChecked);
if (useSwitch) {
apply(checkboxButton, GONE);
apply(switchButton, VISIBLE);
} else {
apply(checkboxButton, VISIBLE);
apply(switchButton, GONE);
}
View.OnClickListener listener = view1 -> {
if (SettingsPreferences.isGenericSettingEnabled(context, preferenceCONST, true)) {
SettingsPreferences.disableGenericSetting(context, preferenceCONST);
AnalyticsHelper.getInstance(context).logScreenEvent(SCREEN_SETTINGS, settingsDisabledAction);
checkboxButton.setChecked(false);
switchButton.setChecked(false);
} else {
SettingsPreferences.enableGenericSetting(context, preferenceCONST);
AnalyticsHelper.getInstance(context).logScreenEvent(SCREEN_SETTINGS, settingsEnabledAction);
checkboxButton.setChecked(true);
switchButton.setChecked(true);
}
};
if (!isProFeature || userIsPro) {
checkboxButton.setEnabled(true);
switchButton.setEnabled(true);
checkboxButton.setOnClickListener(listener);
switchButton.setOnClickListener(listener);
view.setOnClickListener(listener);
} else {
checkboxButton.setChecked(true);
switchButton.setChecked(true);
checkboxButton.setEnabled(false);
switchButton.setEnabled(false);
}
return this;
}