项目作者: Maxr1998

项目描述 :
Android Preferences defined through Kotlin DSL, shown in a RecyclerView
高级语言: Kotlin
项目地址: git://github.com/Maxr1998/ModernAndroidPreferences.git
创建时间: 2018-09-16T15:29:20Z
项目社区:https://github.com/Maxr1998/ModernAndroidPreferences

开源协议:Apache License 2.0

下载


ModernAndroidPreferences

GitHub release
Maven Central
Build status
Lint status
License

Android preferences in Kotlin DSL, displayed in a RecyclerView.

No XML, no troubles with PreferenceManager, Fragments, or styling, no more ListView. :tada:

Code example

  1. // Setup a preference screen
  2. val screen = screen(context) {
  3. pref("first") {
  4. title = "A preference"
  5. summary = "Click me to do stuff"
  6. click {
  7. doStuff()
  8. }
  9. }
  10. pref("second") {
  11. title = "Another one"
  12. iconRes = R.drawable.preference_icon_24dp
  13. }
  14. categoryHeader("more") {
  15. titleRes = R.string.category_more
  16. }
  17. switch("toggle_feature") {
  18. title = "Also supports switches"
  19. }
  20. // and many other preference widgets!
  21. }
  22. // Wrap the created screen in a preference adapter…
  23. val preferencesAdapter = PreferencesAdapter(screen)
  24. // …that can be attached to a RecyclerView
  25. recyclerView.adapter = preferencesAdapter

Example app

Example Activities (with and without using ViewModel)
show advanced info like back handling, saving/restoring scroll position, and using the OnScreenChangeListener.

Screenshots


Click to show

| | |
|:————————————————-:|:————————————————-:|

Include to project

ModernAndroidPreferences is on Maven Central,
so you can get it like any other dependency:

  1. dependencies {
  2. implementation 'de.maxr1998:modernandroidpreferences:2.3.2'
  3. }

NOTE: This library has previously been available as de.Maxr1998.android:modernpreferences on Bintray JCenter,
but was migrated to Sonatype Maven Central in light of the impending JCenter sunsetting.
To get in line with Maven naming standards, it was renamed to de.maxr1998:modernandroidpreferences.

License

Copyright © 2018-2021 Max Rumpf alias Maxr1998

This library is released under the Apache License version 2.0.
If you use this library (or code from it) in your projects, crediting me is appreciated.

The example application however is licensed under the GNU General Public version 3, or any later version.