【问题标题】:Preference ringtone default value偏好铃声默认值
【发布时间】:2011-10-03 12:03:47
【问题描述】:
我的preferences.xml中有这个
<RingtonePreference android:key="ringtone_uri"
android:title="@string/preferences_select_ringtone"
android:showDefault="true" android:srinlent="true"
android:summary="@string/preferences_select_ringtone_summary" />
每次我第一次开始全新安装应用程序时,默认值为静音 :(,当我点击铃声首选项时,对话框打开时默认选择静音。我希望默认情况下“默认铃声”为被选中。我该怎么做
如何将默认值设置为“默认铃声”而不是静音,我不知道为什么这是我的默认值我没有在我的代码中的任何地方设置,静音是 android 系统的默认值。 ..
【问题讨论】:
标签:
android
preference
ringtone
【解决方案1】:
将默认值设置为默认铃声的最简单方法
<RingtonePreference
android:showDefault="true"
android:showSilent="true"
android:defaultValue="content://settings/system/notification_sound"
.......
>
</RingtonePreference>
【解决方案2】:
我正在搜索如何设置铃声的默认值,并意识到当未设置首选项时,该值为空并且默认选择静音。但我这样做
defaultstr = Uri.parse(PreferenceManager.getDefaultSharedPreferences(context).getString("r_uri",
android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()));
//than I do this, I save the default ringtone to my setting
if (defaultstr.equals(android.provider.Settings.System.DEFAULT_RINGTONE_URI)) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("r_uri",
android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()).commit();
}
我希望这对其他人有帮助。顺便说一句,我发现这个解决方法吓坏了,我花了好几个小时才开始思考
【解决方案3】:
只需禁用“静音”项:
<RingtonePreference android:key="ringtone_uri"
android:title="@string/preferences_select_ringtone"
android:showDefault="true" android:srinlent="true"
android:summary="@string/preferences_select_ringtone_summary"
android:showSilent="false">