com.google.android.material.switchmaterial.SwitchMaterial Java Examples
The following examples show how to use
com.google.android.material.switchmaterial.SwitchMaterial.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnalyticsPreferenceDialog.java From CommonUtils with Apache License 2.0 | 6 votes |
@NonNull @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialog_analytics_preference, container, false); SwitchMaterial tracking = layout.findViewById(R.id.analyticsPrefsDialog_tracking); tracking.setChecked(Prefs.getBoolean(CommonPK.TRACKING_ENABLED, true)); tracking.setOnCheckedChangeListener((buttonView, isChecked) -> Prefs.putBoolean(CommonPK.TRACKING_ENABLED, isChecked)); SwitchMaterial crashReport = layout.findViewById(R.id.analyticsPrefsDialog_crashReport); crashReport.setChecked(Prefs.getBoolean(CommonPK.CRASH_REPORT_ENABLED, true)); crashReport.setOnCheckedChangeListener((buttonView, isChecked) -> Prefs.putBoolean(CommonPK.CRASH_REPORT_ENABLED, isChecked)); Button ok = layout.findViewById(R.id.analyticsPrefsDialog_ok); ok.setOnClickListener(v -> dismissAllowingStateLoss()); return layout; }
Example #2
Source File: SwitchMainDemoFragment.java From material-components-android with Apache License 2.0 | 6 votes |
@Override public View onCreateDemoView( LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { View view = layoutInflater.inflate(R.layout.cat_switch, viewGroup, false /* attachToRoot */); ViewGroup switchDemoViewGroup = view.findViewById(R.id.main_viewGroup); View toggledView = layoutInflater.inflate(R.layout.cat_switch_toggled, switchDemoViewGroup, false); switchDemoViewGroup.addView(toggledView); List<SwitchMaterial> toggledSwitches = DemoUtils.findViewsWithType(toggledView, SwitchMaterial.class); SwitchMaterial switchToggle = view.findViewById(R.id.switch_toggle); switchToggle.setOnCheckedChangeListener( (CompoundButton buttonView, boolean isChecked) -> { for (SwitchMaterial switchMaterial : toggledSwitches) { switchMaterial.setEnabled(isChecked); } }); return view; }