Skip to content

只要换个包名,即可平替 Preference,实现卡片式效果!(Just change the package name, you can replace Preference and achieve a card-like effect !)

License

Notifications You must be signed in to change notification settings

pepsimaxin/XPreference

Repository files navigation

XPreference

Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge

Implementation

集成 XPreference 之前,请先将项目更新到 AndroidX 库,如项目使用库较老,请迁移至 AndroidX

Static Badge

  1. 项目目录下
    build.gradle.kts 添加:
implementation 'com.github.pepsimaxin:XPreference:0.0.1'
  1. 工程目录下
    settings.gradle.kts 添加:
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven { url = uri("https://jitpack.io") }
    }
}

Use

✅ 项目中实现 XPreference 卡片效果,只需要「 配置主题 」及「 替换包名 」即可!

  1. 配置主题
<!-- 你的 APP 主题. -->
<style name="Base.Theme.XPreference" parent="Theme.AppCompat.DayNight">
    <!-- 全局替换 preferenceTheme 主题 -->
    <item name="preferenceTheme">@style/Gorgeous.PreferenceThemeOverlay.DayNight</item>
</style>
  1. 替换 PreferenceFragmentCompat

当你使用 Fragment 时,所有配置的 XML 布局,最终是通过 「PreferenceFragmentCompat」 来加载的,而 XPreference SDK 内部对所有的 「Preference」 项做了卡片效果,所以在代码中需要将:

"androidx.preference.PreferenceFragmentCompat" 替换为 "gorgeous.preference.PreferenceFragmentCompat"。

// import androidx.preference.PreferenceFragmentCompat;
   import gorgeous.preference.PreferenceFragmentCompat;

public class DisplayFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.fragment_display, rootKey);
    }
}

License

Copyright (C) Marco, 2024, XPreference Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http:https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

只要换个包名,即可平替 Preference,实现卡片式效果!(Just change the package name, you can replace Preference and achieve a card-like effect !)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages