本文整理匯總了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;
}