---
pageClass: code-page
---

::: warning

Due to maintenance costs, the `YukiHookAPI` will no longer update this document from version `1.3.0` and switch to the API document automatically generated by the Dokka plugin in version `2.0.0`.

:::

::: warning

The English translation of this page has not been completed, you are welcome to contribute translations to us.

You can use the **Chrome Translation Plugin** to translate entire pages for reference.

:::

# ModulePreferenceFragment <span class="symbol">- class</span>

```kotlin:no-line-numbers
abstract class ModulePreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener
```

**Change Records**

`v1.0.78` `added`

**Function Illustrate**

> 这是对使用 `YukiHookAPI` Xposed 模块实现中的一个扩展功能。

此类接管了 `PreferenceFragmentCompat` 并对其实现了 Sp 存储在 Xposed 模块中的全局可读可写。

在你使用 `PreferenceFragmentCompat` 的实例中，将继承对象换成此类。

然后请将重写方法由 `onCreatePreferences` 替换为 `onCreatePreferencesInModuleApp` 即可。

**Function Example**

使用 `ModulePreferenceFragment` 创建一个 `PreferenceFragmentCompat` 对象。

> The following example

```kotlin
class SettingsFragment : ModulePreferenceFragment() {

    override fun onCreatePreferencesInModuleApp(savedInstanceState: Bundle?, rootKey: String?) {
        setPreferencesFromResource(R.xml.settings_preferences, rootKey)
        // Your code here.
    }
}
```

其余用法与 `PreferenceFragmentCompat` 保持一致。

## onCreatePreferencesInModuleApp <span class="symbol">- method</span>

```kotlin:no-line-numbers
abstract fun onCreatePreferencesInModuleApp(savedInstanceState: Bundle?, rootKey: String?)
```

**Change Records**

`v1.0.78` `added`

**Function Illustrate**

> 对接原始方法 `onCreatePreferences`。

## onSharedPreferenceChanged <span class="symbol">- method</span>

```kotlin:no-line-numbers
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?)
```

**Change Records**

`v1.0.78` `added`

**Function Illustrate**

> 实现了 `SharedPreferences.OnSharedPreferenceChangeListener` 的原生监听功能。

**Function Example**

::: warning

在使用 **onSharedPreferenceChanged** 时请保留 super 方法。

:::

> The following example

```kotlin
class SettingsFragment : ModulePreferenceFragment() {

    override fun onCreatePreferencesInModuleApp(savedInstanceState: Bundle?, rootKey: String?) {
        // ...
    }

    override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
        super.onSharedPreferenceChanged(sharedPreferences, key)
        // Your code here.
    }
}
```