Android - How Do I Set A Preference In Code

前端 未结 3 2224
借酒劲吻你
借酒劲吻你 2020-12-02 10:59

I have an Android application in which I have my preferences in an XML file, which works fine. I now want to set one of the preferences using code instead of displaying the

3条回答
  •  心在旅途
    2020-12-02 12:02

    I tried this but didn't work:

    SharedPreferences settings = getSharedPreferences(String n, MODE_PRIVATE);
    

    Try this instead:

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    

提交回复
热议问题