本文整理匯總了Java中android.preference.SwitchPreference.setTitle方法的典型用法代碼示例。如果您正苦於以下問題:Java SwitchPreference.setTitle方法的具體用法?Java SwitchPreference.setTitle怎麽用?Java SwitchPreference.setTitle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.preference.SwitchPreference
的用法示例。
在下文中一共展示了SwitchPreference.setTitle方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.preference.SwitchPreference; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_wireless_socket);
setHasOptionsMenu(true);
PreferenceScreen preferenceScreen = this.getPreferenceScreen();
PreferenceCategory preferenceCategory = new PreferenceCategory(preferenceScreen.getContext());
preferenceCategory.setTitle("Wireless sockets");
preferenceScreen.addPreference(preferenceCategory);
for (int index = 0; index < WirelessSocketService.getInstance().GetDataList().getSize(); index++) {
WirelessSocket wirelessSocket = WirelessSocketService.getInstance().GetDataList().getValue(index);
SwitchPreference preference = new SwitchPreference(preferenceScreen.getContext());
preference.setTitle(wirelessSocket.GetName());
preference.setKey(wirelessSocket.GetSettingsKey());
preference.setDefaultValue(false);
preferenceCategory.addPreference(preference);
bindPreferenceSummaryToValue(preference);
}
}
示例2: addSwitchPreferenceBasedOnCheckBoxPreference
import android.preference.SwitchPreference; //導入方法依賴的package包/類
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
final PreferenceGroup group) {
final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
switchPref.setTitle(checkBox.getTitle());
switchPref.setKey(checkBox.getKey());
switchPref.setOrder(checkBox.getOrder());
switchPref.setPersistent(checkBox.isPersistent());
switchPref.setEnabled(checkBox.isEnabled());
switchPref.setChecked(checkBox.isChecked());
switchPref.setSummary(checkBox.getSummary());
switchPref.setSummaryOn(checkBox.getSummaryOn());
switchPref.setSummaryOff(checkBox.getSummaryOff());
switchPref.setSwitchTextOn(EMPTY_TEXT);
switchPref.setSwitchTextOff(EMPTY_TEXT);
group.addPreference(switchPref);
switchPref.setDependency(checkBox.getDependency());
}
示例3: setupDaydreamPreferences
import android.preference.SwitchPreference; //導入方法依賴的package包/類
private void setupDaydreamPreferences() {
if (!isAdded() ) return;
enablePreference("autostart", !Utility.isConfiguredAsDaydream(mContext) );
Preference pref = findPreference("autostart");
boolean on = pref.isEnabled();
String summary = on ? "" : getString(R.string.autostart_message_disabled);
pref.setSummary(summary);
PreferenceCategory category = (PreferenceCategory) findPreference("category_behaviour");
removePreference("force_auto_rotation");
if (!on) {
SwitchPreference forceAutoRotation = new SwitchPreference(mContext);
forceAutoRotation.setKey("force_auto_rotation");
forceAutoRotation.setTitle(getString(R.string.force_auto_rotation));
forceAutoRotation.setSummary(getString(R.string.force_auto_rotation_summary));
forceAutoRotation.setDefaultValue(false);
category.addPreference(forceAutoRotation);
}
}
示例4: getVibrateDuringDndPreference
import android.preference.SwitchPreference; //導入方法依賴的package包/類
private SwitchPreference getVibrateDuringDndPreference() {
SwitchPreference vibrateDuringDnd = new SwitchPreference(getActivity());
vibrateDuringDnd.setKey("pref_key_vibrate_during_dnd");
vibrateDuringDnd
.setTitle(getActivity().getString
(R.string.vibrate_during_dnd_preference_title));
vibrateDuringDnd
.setSummary(getActivity().getString
(R.string.vibrate_during_dnd_preference_summary));
vibrateDuringDnd.setDefaultValue(true);
return vibrateDuringDnd;
}
示例5: createSwitchPreference
import android.preference.SwitchPreference; //導入方法依賴的package包/類
private SwitchPreference createSwitchPreference(String dataSourceType) {
SwitchPreference switchPreference = new SwitchPreference(getActivity());
switchPreference.setKey(dataSourceType);
String title = dataSourceType;
title = title.replace("_", " ");
title = title.substring(0, 1).toUpperCase() + title.substring(1).toLowerCase();
switchPreference.setTitle(title);
switchPreference.setOnPreferenceChangeListener(onPreferenceChangeListener);
switchPreference.setEnabled(isSensorSupported(dataSourceType));
switch (dataSourceType) {
case (DataSourceType.ACCELEROMETER):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Accelerometer.frequencyOptions));
break;
case (DataSourceType.GYROSCOPE):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Gyroscope.frequencyOptions));
break;
case (DataSourceType.AMBIENT_TEMPERATURE):
// switchPreference.setOnPreferenceClickListener(alertDialogFrequency(AmbientTemperature.frequencyOptions));
break;
case (DataSourceType.COMPASS):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Compass.frequencyOptions));
break;
case (DataSourceType.AMBIENT_LIGHT):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(AmbientLight.frequencyOptions));
break;
case (DataSourceType.PRESSURE):
// switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Pressure.frequencyOptions));
break;
case (DataSourceType.PROXIMITY):
// switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Proximity.frequencyOptions));
break;
}
return switchPreference;
}
示例6: createPreferences
import android.preference.SwitchPreference; //導入方法依賴的package包/類
@SuppressLint("SdCardPath")
/* We hardcode /sdcard/ because we want the user to use /sdcard/ instead of emulated
* sdcard file paths such as /storage/emulated/0/ that was introduced in Android 4.2
* due to the multi-user account feature. */
private PreferenceScreen createPreferences(final Context ctx) {
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
prefFontFolder = new Preference(this);
prefFontFolder.setTitle(getResources().getString(R.string.font_folder_title));
prefFontFolder.setKey(Common.KEY_FOLDER_FONT);
prefFontFolder.setOnPreferenceClickListener(new OnPreferenceClickListener(){
@Override
public boolean onPreferenceClick(Preference arg0) {
Intent i = new Intent(ctx, DirectoryChooserActivity.class);
i.putExtra(DirectoryChooserActivity.EXTRA_INITIAL_DIRECTORY, "/sdcard/");
startActivityForResult(i, REQUEST_DIRECTORY);
return true;
}
});
root.addPreference(prefFontFolder);
prefFontEverythingEnable = new SwitchPreference(this);
prefFontEverythingEnable.setTitle(getResources().getString(R.string.font_everything_enable_title));
prefFontEverythingEnable.setSummary(getResources().getString(R.string.font_everything_enable_summary));
prefFontEverythingEnable.setKey(Common.KEY_ENABLE_EVERY_APP);
root.addPreference(prefFontEverythingEnable);
updateSummary();
return root;
}
示例7: onCreate
import android.preference.SwitchPreference; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
notificationSwitch =
(SwitchPreference)findPreference(
getString(R.string.notifications_switch_key) );
notificationSwitch.setTitle(R.string.notifications_switch_title);
if ( notificationSwitch.isChecked() ) {
notificationSwitch.setSummary( alarmNextDueString() );
} else {
notificationSwitch.setSummary(
R.string.notifications_switched_off_confirmation);
}
notificationSwitch.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
boolean switchValue = (Boolean)newValue;
Log.d(LOG_TAG, "New value for notification switch will be "
+ switchValue);
if (switchValue == false) {
Log.d(LOG_TAG, "Disabling notifications... ");
Alarms.getInstance().cancel();
SettingsFragment.this.notificationSwitch.setSummary(
R.string.notifications_switched_off_confirmation);
showToast(R.string.notifications_switched_off_confirmation);
} else {
Log.d(LOG_TAG, "Enabling notifications... ");
AlarmTimeInterval interval = getAlarmInterval();
Alarms.getInstance().set(interval);
SettingsFragment.this.notificationSwitch.setSummary(
alarmNextDueString() );
showToast(R.string.notifications_switched_on_confirmation,
interval.getDays(),
interval.getHours(),
interval.getMinutes() );
}
return true;
}
}
);
preferenceListener = new NextAlarmPreferenceListener();
getActivity().getSharedPreferences(LOG_TAG, Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(preferenceListener);
}
示例8: updateList
import android.preference.SwitchPreference; //導入方法依賴的package包/類
private void updateList(List<ServiceInfo> services) {
final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
Collections.sort(services, new PackageItemInfo.DisplayNameComparator(mPM));
for (ServiceInfo service : services) {
final ComponentName cn = new ComponentName(service.packageName, service.name);
final String title = service.loadLabel(mPM).toString();
final SwitchPreference pref = new SwitchPreference(mContext);
pref.setPersistent(false);
pref.setIcon(service.loadIcon(mPM));
pref.setTitle(title);
pref.setChecked(mServiceListing.isEnabled(cn));
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enable = (boolean) newValue;
return setEnabled(cn, title, enable);
}
});
screen.addPreference(pref);
}
}