【Android】PA4D_CH7 檔案、儲存狀態和喜好設定

來源:互聯網
上載者:User

標籤:android   des   style   blog   class   code   

本章主要知識點如下:

  • 瞭解Shared Preferences
  • 介面OnSharedPreferenceChangeListener, 每當添加、移除或者修改一個特定的Shared Preference 時候可以調用一個回呼函數
  • 建立Preference Screen(喜好設定架構)
    • PreferenceActivity,  適用於API Level 11 (SDK3.0) 以前(xml 配置)
    • PreferenceFragment, 適用於API Level 11 (SKD3.0) 以後,相容平板 (preserence-header配置)
    • Activity中根據目前的版本號動態配置二者
      Class c = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? UserPreferences.class                    : FragmentPreferences.class;Intent i = new Intent(this, c);
    • Preference Screen中,  使用了ListPreference控制項 , 預設儲存的是String類型的值
    • 可以繼承Preference Screen中的組件, 並且重寫組件,實現各種功能,比如在設定中選擇字型的顏色
  • 在Activity銷毀或者隱藏以後,儲存Fragment的狀態
    setRetainInstance(true);
  • 添加靜態檔案作為資源
  • 使用Environment擷取目錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.