當前位置: 首頁>>代碼示例>>Java>>正文


Java Switch類代碼示例

本文整理匯總了Java中android.widget.Switch的典型用法代碼示例。如果您正苦於以下問題:Java Switch類的具體用法?Java Switch怎麽用?Java Switch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Switch類屬於android.widget包,在下文中一共展示了Switch類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.widget.Switch; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = findViewById(R.id.text);
    updateText();
    Switch s = findViewById(R.id.switch_widget);
    s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                RedirectStorage.enable(new PathCallback() {
                    @Override
                    public File onModify(File original) {
                        return getFilesDir();
                    }
                });
            } else {
                RedirectStorage.disable();
            }
            updateText();
        }
    });
}
 
開發者ID:Trumeet,項目名稱:RedirectStorage,代碼行數:25,代碼來源:MainActivity.java

示例2: onSwitchChanged

import android.widget.Switch; //導入依賴的package包/類
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
    if (DEBUG) Log.d(TAG, "onSwitchChanged " + isChecked);
    if (mDisableListeners) return;
    final boolean enabled = isChecked;
    if (enabled == mRule.enabled) return;
    MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ENABLE_RULE, enabled);
    if (DEBUG) Log.d(TAG, "onSwitchChanged enabled=" + enabled);
    mRule.enabled = enabled;
    mRule.snoozing = false;
    setZenModeConfig(mConfig);
    if (enabled) {
        final int toastText = getEnabledToastText();
        if (toastText != 0) {
            mEnabledToast = Toast.makeText(mContext, toastText, Toast.LENGTH_SHORT);
            mEnabledToast.show();
        }
    } else {
        if (mEnabledToast != null) {
            mEnabledToast.cancel();
        }
    }
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:24,代碼來源:ZenModeRuleSettingsBase.java

示例3: initView

import android.widget.Switch; //導入依賴的package包/類
private void initView(Context context) {
    rootView = View.inflate(context, R.layout.widget_ver_controller, this);

    ivBack = (ImageView) findViewById(R.id.iv_thelive_back);
    verMediaControll = findViewById(R.id.verMediaControll);
    infoContainer = findViewById(R.id.infoContainer);
    ll_four_container = (LinearLayout) findViewById(R.id.ll_four_container);
    theliveMore = (ImageView) findViewById(R.id.iv_thelive_more);
    check_gift_switch = (CheckBox) findViewById(R.id.check_gift_switch);
    check_live_pause = (CheckBox) findViewById(R.id.check_live_pause);
    ivFullscreen = (ImageView) findViewById(R.id.iv_thelive_fullscreen);
    theliveNum = (TextView) findViewById(R.id.tv_thelive_num);
    ll_jubao_and_share = (LinearLayout) findViewById(R.id.ll_jubao_and_share);
    tv_jubao = (TextView) findViewById(R.id.tv_jubao);
    tv_share = (TextView) findViewById(R.id.tv_share);
    live_vertical_bottom = (FrameLayout) findViewById(R.id.live_vertical_bottom);

    //info
    ic_head = (ImageView) findViewById(R.id.ic_head);
    nickName = (TextView) findViewById(R.id.nickName);
    titleName = (TextView) findViewById(R.id.title);
    ivIsFocus = (ImageView) findViewById(R.id.iv_thelive_focus);
    swRemind = (Switch) findViewById(R.id.switchview_remind);

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:VerticalMediaControllView.java

示例4: onCreateView

import android.widget.Switch; //導入依賴的package包/類
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
    View view = inflater.inflate(R.layout.debug_drawer_mock_ble, parent, false);

    Switch mockBle = view.findViewById(R.id.debug_drawer_ble_mock);
    mockBle.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            mainActivity.provideBluetoothUtil(new BluetoothUtilMockImpl());
        } else {
            mainActivity.provideBluetoothUtil(new BluetoothUtilImpl());
        }

    });

    return view;
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:18,代碼來源:DebugDrawerMockBle.java

示例5: _initialize

import android.widget.Switch; //導入依賴的package包/類
@Hide
@Override
public void _initialize(final BA ba, Object activityClass, String EventName) {
	final Switch _switch = new Switch(ba.context);
	final String eventName = EventName.toLowerCase(BA.cul);
	setObject(_switch);
	innerInitialize(ba, eventName, true);
	if (ba.subExists(eventName + "_checkedchange")) {
		getObject().setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				ba.raiseEventFromUI(_switch,eventName + "_checkedchange", isChecked);
			}
			
		});
	}
}
 
開發者ID:AnywhereSoftware,項目名稱:B4A_ViewsEx,代碼行數:19,代碼來源:SwitchWrapper.java

示例6: onFinishInflate

import android.widget.Switch; //導入依賴的package包/類
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mIconView = (ImageView) findViewById(R.id.icon);
    mMountSwitch = (Switch) findViewById(R.id.mount_switch);
    mLabelView = (TextView) findViewById(R.id.label);
    mVersionView = (TextView) findViewById(R.id.version);
    mRunView = (TextView) findViewById(R.id.run);
    mInfoView = (TextView) findViewById(R.id.info);
    mAddToLauncherView = (TextView) findViewById(R.id.add_to_launcher);

    mMountSwitch.setOnCheckedChangeListener(this);
    mRunView.setOnClickListener(this);
    mInfoView.setOnClickListener(this);
    mAddToLauncherView.setOnClickListener(this);
}
 
開發者ID:mthli,項目名稱:Mount,代碼行數:18,代碼來源:PackageSettingLayout.java

示例7: SwitchItem

import android.widget.Switch; //導入依賴的package包/類
public SwitchItem(Context context, String title, String key, boolean defaultValue) {
    super(context);
    this.mKey = key;
    this.mDefaultValue = defaultValue;

    View.inflate(getContext(), R.layout.view_switch_item, this);

    TextView titleView = (TextView) findViewById(R.id.title);
    titleView.setText(title);

    mSwitchView = (Switch) findViewById(R.id.switcher);
    mSwitchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SharedPreferences.Editor editor = App.sp.edit();
        editor.putBoolean(key, isChecked);
        editor.apply();
    });
}
 
開發者ID:dss886,項目名稱:Transmis,代碼行數:18,代碼來源:SwitchItem.java

示例8: referenceViews

import android.widget.Switch; //導入依賴的package包/類
private void referenceViews() {
    switchNotifications = (Switch) findViewById(R.id.switchNotifications);
    switchNotificationSound = (Switch) findViewById(R.id.switchNotificationSound);
    switchNotificationLight = (Switch) findViewById(R.id.switchNotificationLight);
    switchNotificationVibrations = (Switch) findViewById(R.id.switchNotificationVibrations);
    textViewNotificationPeriod = (TextView) findViewById(R.id.textViewNotificationPeriod);

    String notification = getResources().getString(R.string.notification);
    String notificationSub = getResources().getString(R.string.notification_sub_2);
    Span.span(notification, notificationSub, switchNotifications);

    String notificationSound = getResources().getString(R.string.notification_sound);
    Span.span(notificationSound, switchNotificationSound);

    String notificationLight = getResources().getString(R.string.notification_light);
    Span.span(notificationLight, switchNotificationLight);

    String notificationVibration = getResources().getString(R.string.notification_vibration);
    Span.span(notificationVibration, switchNotificationVibrations);

    String notificationPeriod = getResources().getString(R.string.notification_period);
    String notificationPeriodSub = getResources().getString(R.string.notification_period_sub);
    Span.span(notificationPeriod, notificationPeriodSub, textViewNotificationPeriod);
}
 
開發者ID:kerick-jeff,項目名稱:MyBP,代碼行數:25,代碼來源:NotificationActivity.java

示例9: referenceViews

import android.widget.Switch; //導入依賴的package包/類
private void referenceViews() {
    switchProfile = (Switch) findViewById(R.id.switchProfile);
    switchGoogle = (Switch) findViewById(R.id.switchGoogle);
    textViewNotifications = (TextView) findViewById(R.id.textViewNotifications);
    switchCurrency = (Switch) findViewById(R.id.switchCurrency);

    String profile = getResources().getString(R.string.profile);
    String profileSub = getResources().getString(R.string.profile_sub);
    Span.span(profile, profileSub, switchProfile);

    String profileGoogle = getResources().getString(R.string.profile_google);
    String profileGoogleSub = getResources().getString(R.string.profile_google_sub);
    Span.span(profileGoogle, profileGoogleSub, switchGoogle);

    String notification = getResources().getString(R.string.notification);
    String notificationSub = getResources().getString(R.string.notification_sub);
    Span.span(notification, notificationSub, textViewNotifications);

    String currency = getResources().getString(R.string.currency);
    String currencySub = getResources().getString(R.string.currency_sub);
    Span.span(currency, currencySub, switchCurrency);
}
 
開發者ID:kerick-jeff,項目名稱:MyBP,代碼行數:23,代碼來源:SettingsActivity.java

示例10: BlockingItemViewHolder

import android.widget.Switch; //導入依賴的package包/類
BlockingItemViewHolder(View itemView, final BrowserFragment fragment) {
    super(itemView);

    this.fragment = fragment;

    final Switch switchView = itemView.findViewById(R.id.blocking_switch);
    switchView.setChecked(fragment.getSession().isBlockingEnabled());
    switchView.setOnCheckedChangeListener(this);

    final View helpView = itemView.findViewById(R.id.help_trackers);
    helpView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (browserFragment != null) {
                browserFragment.onClick(view);
            }
        }
    });

    trackerCounter = itemView.findViewById(R.id.trackers_count);

    updateTrackers(fragment.getSession().getBlockedTrackers().getValue());
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:24,代碼來源:BlockingItemViewHolder.java

示例11: onCreateOptionsMenu

import android.widget.Switch; //導入依賴的package包/類
/**
 * Creates menu functionality.
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.menu_nearby_events, menu);
    final MenuItem nearbyToggle = menu.findItem(R.id.nearbyEventSwitch);
    final Switch actionView = (Switch) nearbyToggle.getActionView().findViewById(R.id.mapSwitch);
    actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked){//Needs to call some method otherwise doesn't work
                addNearbyMarkers(gmap);
            }
            else{
                addAllMarkers(gmap);
            }

        }
    });
    return super.onCreateOptionsMenu(menu);
}
 
開發者ID:CMPUT301F17T09,項目名稱:GoalsAndHabits,代碼行數:26,代碼來源:MapFiltersActivity.java

示例12: onCreate

import android.widget.Switch; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);



    mSwitch=(Switch)findViewById(R.id.switch1);
    mSwitch.setChecked(checkSystemWritePermission());
    mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // 開啟switch,設置提示信息
                getPermission();
            } else {
                // 關閉swtich,設置提示信息
                mSwitch.setText(getString(R.string.text_off));
            }
        }
    });
}
 
開發者ID:gojuukaze,項目名稱:ScreenOffTime,代碼行數:24,代碼來源:MainActivity.java

示例13: initView

import android.widget.Switch; //導入依賴的package包/類
private void initView()
{
    switch_voice= (Switch) findViewById(R.id.switch_voice);
    switch_sms= (Switch) findViewById(R.id.switch_sms);
    ll_check_version= (LinearLayout) findViewById(R.id.ll_check_version);
    tv_version_name= (TextView) findViewById(R.id.tv_version_name);
    ll_scan_qrcode= (LinearLayout) findViewById(R.id.ll_scan_qrcode);
    ll_my_qrcode= (LinearLayout) findViewById(R.id.ll_my_qrcode);
    ll_location= (LinearLayout) findViewById(R.id.ll_location);
    //獲取當前版本信息顯示在界麵上
    showCurrentVersionInfo();
    //為各種開關設置監聽事件
    switch_voice.setOnClickListener(this);
    switch_sms.setOnClickListener(this);
    ll_check_version.setOnClickListener(this);
    ll_scan_qrcode.setOnClickListener(this);
    ll_my_qrcode.setOnClickListener(this);
    ll_location.setOnClickListener(this);
    //進入界麵後讀取之前保存的開關狀態
    switch_voice.setChecked(SharedUtils.getBoolean("voice_key",false));
    switch_sms.setChecked(SharedUtils.getBoolean("sms_key",false));
}
 
開發者ID:WindFromFarEast,項目名稱:SmartButler,代碼行數:23,代碼來源:SettingActivity.java

示例14: getView

import android.widget.Switch; //導入依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    InstalledApp app = getItem(position);
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_app, parent, false);
    }
    // Lookup view for data population


    appImage = (ImageView) convertView.findViewById(R.id.appImage);
    appPackage = (Switch) convertView.findViewById(R.id.appSwitch);
    appName = (TextView) convertView.findViewById(R.id.appName);
    appImage.setImageDrawable(app.image);
    appPackage.setText(app.packageName);
    appName.setText(app.name);

    // Return the completed view to render on screen
    return convertView;
}
 
開發者ID:mcosti,項目名稱:notifications-forwarder,代碼行數:22,代碼來源:AppsAdapter.java

示例15: createSlaveView

import android.widget.Switch; //導入依賴的package包/類
@Override
public View createSlaveView() {
    // TODO Auto-generated method stub
    TVMenuItem slaveView;
    if(findViewById(R.id.info_text)!=null && findViewById(R.id.info_text) instanceof RadioButton){
        slaveView = (TVMenuItem)LayoutInflater.from(mContext)
                .inflate(R.layout.menu_item_checkable_layout, null);
    }
    else if(findViewById(R.id.info_text)!=null && findViewById(R.id.info_text) instanceof Switch){
        slaveView = (TVMenuItem)LayoutInflater.from(mContext)
                .inflate(R.layout.menu_item_switchable_layout, null);
    }
    else{
        slaveView = (TVMenuItem)(View)LayoutInflater.from(mContext)
                .inflate(R.layout.menu_item_layout, null);
    }
    setSlaveView(slaveView);
    return slaveView;
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:20,代碼來源:TVMenuItem.java


注:本文中的android.widget.Switch類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。