本文整理了Java中android.widget.Switch.<init>()
方法的一些代码示例,展示了Switch.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Switch.<init>()
方法的具体详情如下:
包路径:android.widget.Switch
类名称:Switch
方法名:<init>
暂无
代码示例来源:origin: lygttpod/SuperTextView
mSwitch = new Switch(mContext);
代码示例来源:origin: trishika/DroidUPnP
public MyPrefsHeaderAdapter(Context context, List<Header> objects)
{
super(context, 0, objects);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mContentDirectoryEnabler = new ContentDirectoryEnabler(context, new Switch(context));
}
代码示例来源:origin: mooshim/Mooshimeter-AndroidApp
Switch makeSwitch(boolean checked, final BooleanRunnable cb) {
Switch s = new Switch(mContext);
s.setChecked(checked);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cb.arg = isChecked;
cb.run();
}
});
return s;
}
代码示例来源:origin: mooshim/Mooshimeter-AndroidApp
Switch makeSwitch(boolean checked, final BooleanRunnable cb) {
Switch s = new Switch(mContext);
s.setChecked(checked);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cb.arg = isChecked;
cb.run();
}
});
return s;
}
public Switch makeSwitchForMeterPreference(final String pref_name) {
代码示例来源:origin: mooshim/Mooshimeter-AndroidApp
Switch makeSwitch(boolean checked, final BooleanRunnable cb) {
Switch s = new Switch(mContext);
s.setChecked(checked);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cb.arg = isChecked;
cb.run();
}
});
s.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
return s;
}
public Switch makeSwitchForPreference(final String pref_name) {
代码示例来源:origin: googlesamples/android-AppRestrictionEnforcer
private void updateApprovals(Context context, String[] approvals,
String[] selectedApprovals) {
mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals);
mLayoutApprovals.removeAllViews();
for (String approval : approvals) {
Switch sw = new Switch(context);
sw.setText(approval);
sw.setTag(approval);
sw.setChecked(Arrays.asList(selectedApprovals).contains(approval));
sw.setOnCheckedChangeListener(this);
sw.setId(R.id.approval);
mLayoutApprovals.addView(sw);
}
}
代码示例来源:origin: renyuneyun/Easer
@NonNull
@Override
public ViewGroup onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
LinearLayout view = new LinearLayout(getContext());
view.setOrientation(LinearLayout.VERTICAL);
LinearLayout auto_layout = new LinearLayout(getContext());
auto_layout.setOrientation(LinearLayout.HORIZONTAL);
TextView tv_auto = new TextView(getContext());
tv_auto.setText(getResources().getString(R.string.operation_brightness_desc_autobrightness));
mIsAuto = new Switch(getContext());
mIsAuto.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mBrightnessLevel = new SeekBar(getContext());
mBrightnessLevel.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mBrightnessLevel.setMax(255);
mBrightnessLevel.setEnabled(false);
mIsAuto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
mBrightnessLevel.setEnabled(false);
else
mBrightnessLevel.setEnabled(true);
}
});
auto_layout.addView(mIsAuto);
auto_layout.addView(tv_auto);
view.addView(auto_layout);
view.addView(mBrightnessLevel);
return view;
}
代码示例来源:origin: nvanbenschoten/motion
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.parallax, menu);
// Add parallax toggle
final Switch mParallaxToggle = new Switch(getActivity());
mParallaxToggle.setPadding(0, 0, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getResources().getDisplayMetrics()), 0);
mParallaxToggle.setChecked(mParallaxSet);
mParallaxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mBackground.registerSensorManager();
} else {
mBackground.unregisterSensorManager();
}
mParallaxSet = isChecked;
}
});
MenuItem switchItem = menu.findItem(R.id.action_parallax);
if (switchItem != null)
switchItem.setActionView(mParallaxToggle);
// Set lock/ unlock orientation text
if (mPortraitLock) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
MenuItem orientationItem = menu.findItem(R.id.action_portrait);
if (orientationItem != null)
orientationItem.setTitle(R.string.action_unlock_portrait);
}
}
代码示例来源:origin: androidmalin/JakeWharton-Scalpel-Sample
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.sample_activity);
ButterKnife.inject(this);
pagerView.setAdapter(new SamplePagerAdapter(this));
Switch enabledSwitch = new Switch(this);
enabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (first) {
first = false;
Toast.makeText(SampleActivity.this, R.string.first_run, LENGTH_LONG).show();
}
scalpelView.setLayerInteractionEnabled(isChecked);
invalidateOptionsMenu();
}
});
ActionBar actionBar = getActionBar();
actionBar.setCustomView(enabledSwitch);
actionBar.setDisplayOptions(DISPLAY_SHOW_TITLE | DISPLAY_SHOW_CUSTOM);
}
代码示例来源:origin: emmaguy/clean-status-bar
private void initSwitch() {
Switch masterSwitch = new Switch(this);
masterSwitch.setChecked(CleanStatusBarService.isRunning());
masterSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Intent service = new Intent(MainActivity.this, CleanStatusBarService.class);
if (b) {
startService(service);
} else {
stopService(service);
}
}
});
final ActionBar bar = getSupportActionBar();
final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.master_switch_margin_right);
bar.setCustomView(masterSwitch, lp);
bar.setDisplayShowCustomEnabled(true);
}
代码示例来源:origin: marzika/Snapprefs
private void applyLogTypeSwitches(LinearLayout layout) {
LogType[] logTypes = Logger.LogType.values();
final float scale = getContext().getResources().getDisplayMetrics().density;
HashSet<String> activeTypes = Logger.getActiveLogTypes();
for (LogType logType : logTypes) {
Switch logSwitch = new Switch(layout.getContext());
int pad = (int) (10f * scale);
logSwitch.setPadding(pad, pad / 2, pad, pad / 2);
logSwitch.setText(logType.name());
logSwitch.setChecked(activeTypes.contains(logType.name()));
logSwitch.setTextSize(7f * scale);
logSwitch.setTextColor(Color.GRAY);
logSwitch.setTag(logType.name());
logSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean state) {
String tag = (String) compoundButton.getTag();
Logger.setLogTypeState(tag, state);
}
});
layout.addView(logSwitch);
}
}
}
代码示例来源:origin: trishika/DroidUPnP
addPreferencesFromResource(R.xml.contentdirectory);
Switch actionBarSwitch = new Switch(activity);
代码示例来源:origin: linglongxin24/ARDevelopDemo
Switch newSwitchView = new Switch(mActivity);
newSwitchView.setText(text);
代码示例来源:origin: EthACKdotOrg/orWall
boolean initSupported = Iptables.initSupported();
Switch initScript = new Switch(getActivity());
initScript.setChecked( (enforceInit && initSupported) );
initScript.setText(getString(R.string.wizard_init_script_text));
Switch rootStatus = new Switch(getActivity());
rootStatus.setChecked(RootCommands.rootAccessGiven());
rootStatus.setEnabled(false);
Switch iptablesStatus = new Switch(getActivity());
iptablesStatus.setChecked(Iptables.iptablesExists());
iptablesStatus.setEnabled(false);
Switch iptablesComments = new Switch(getActivity());
iptablesComments.setChecked(iptables.getSupportComment());
iptablesComments.setEnabled(false);
Switch orbotStatus = new Switch(getActivity());
orbotStatus.setChecked(Util.isOrbotInstalled(getActivity()));
orbotStatus.setEnabled(false);
代码示例来源:origin: Odoo-mobile/framework
switch (mWidget) {
case Switch:
mSwitch = new Switch(mContext);
mSwitch.setLayoutParams(params);
mSwitch.setOnCheckedChangeListener(this);
代码示例来源:origin: iAcn/BiliNeat
Switch sw = new Switch(context, attrs);
内容来源于网络,如有侵权,请联系作者删除!