大佬教程收集整理的这篇文章主要介绍了处理没有魔术字符串的Android首选项,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<EditTextPreference android:key="@String/preferences_pdn_key" android@R_723_6964@="@String/preferences_pdn_title" android:sumMary="@String/preferences_pdn_sumMary" android:dialogmessage="@String/input_pdn_message" />@H_772_2@在values / Strings.xml文件中:
... <String name="preferences_pdn_key">pdn</String> ...@H_772_2@然后,您可以从您的活动或偏好活动中引用偏好:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String pdnKey = getString(R.String.prefernece_pdn_key); String pdn = sharedPreferences.getString(pdnKey,null);@H_772_2@如果你不喜欢从字符串资源中获取首选项,那么你可以再做一个技巧:
public class Preferencenames { /* categories */ public static final String LoginCategory = MyApplication.getresourceString(R.String.preferences_login_category_key); ... /* preferences */ public static final String Pdn = MyApplication.getresourceString(R.String.preferences_pdn_key); ... }@H_772_2@所以你现在可以用下面的方式引用你的偏好键:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String pdn = sharedPreferences.getString(Preferencenames.Pdn,null);@H_772_2@这里是您的MyApplication类应如下所示:
public class MyApplication extends Application { private static VvmApplication s_instance; public MyApplication(){ s_instance = this; } public static Context getContext(){ return s_instance; } public static String getresourceString(int resId){ return getContext().getString(resId); } }@H_772_2@另外你需要添加下一件事你的AndroidManifest.xml:
<application android:name="com.mypackage.application.MyApplication" ... > ... </application>
以上是大佬教程为你收集整理的处理没有魔术字符串的Android首选项全部内容,希望文章能够帮你解决处理没有魔术字符串的Android首选项所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。