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


Java SwitchCompat.setEnabled方法代碼示例

本文整理匯總了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);
}
 
開發者ID:ayushghd,項目名稱:iSPY,代碼行數:24,代碼來源:TrackerActivity.java

示例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();
        }
    }
}
 
開發者ID:andreacioni,項目名稱:KeeLink,代碼行數:25,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:jpmeijers,項目名稱:ttnmapper_android_v2,代碼行數:14,代碼來源:MapsActivity.java

示例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);
}
 
開發者ID:jpmeijers,項目名稱:ttnmapper_android_v2,代碼行數:10,代碼來源:MapsActivity.java

示例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;
}
 
開發者ID:RedInput,項目名稱:Notification-Blocker,代碼行數:32,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:albertogiunta,項目名稱:justintrain-client-android,代碼行數:45,代碼來源:ItemBuilder.java


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