PreferenceFragmentCompat 需要设置preferenceTheme [英] PreferenceFragmentCompat requires preferenceTheme to be set

查看:42
本文介绍了PreferenceFragmentCompat 需要设置preferenceTheme的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用来自 v7 首选项支持库的新 PreferenceFragmentCompat:

本机偏好:

解决方案

现在可以非常轻松地使用该库.这是执行此操作的最快方法,但您应该查看自述文件了解更多信息.

1.更新模块的 gradle 文件:

编译'com.takisoft.fix:preference-v7:27.0.0.0'

2.使用适当的类作为片段的基础

您可以使用 PreferenceFragmentCompatPreferenceFragmentCompatDividers.

(在导入PreferenceFragmentCompat时注意适当的包名!)

3.使用合适的主题

将包含 Activity 的主题设置为 @style/PreferenceFixTheme 的变体,例如 NoActionBar、Light 等.

<块引用>

有关更多信息和使用技巧,请访问项目页面.

<小时>

P.S.在本节中,您可以找到导致创建库的详细解决方案,但我决定将其删除,因为它可能会令人困惑.如果您对这些步骤感到好奇,您仍然可以在此答案的修订历史中找到它们.

With the new PreferenceFragmentCompat from the v7 Preference Support Library: http://developer.android.com/tools/support-library/features.html#v7-preference, I get this error

E  java.lang.IllegalStateException: Must specify preferenceTheme in theme
E      at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:202)

What theme should be set?

Update: I have tried using

<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

as suggested by @Bogato but it doesn't look right and looks very Holo even on Lollipop.

Support library:

Native preferences:

解决方案

The sample project can be found here

The bugfix is available as a gradle dependency

Now one can use the library pretty easy. Here are quickest way to do so, but you should check out the README for more info.

1. Update your module's gradle file:

compile 'com.takisoft.fix:preference-v7:27.0.0.0'

2. Use the appropriate class as your fragment's base

You can use either PreferenceFragmentCompat or PreferenceFragmentCompatDividers.

(Watch out for the appropriate package name when importing PreferenceFragmentCompat!)

3. Use the appropriate theme

Set your containing Activity's theme to a variant of @style/PreferenceFixTheme, like NoActionBar, Light, etc.

For more info and usage tips, go to the project's page.


P.S. In this section you could find the detailed solution that led to creation of the library, but I decided to remove it because it might be confusing. If you're curious about the steps, you can still find them in the revision history of this answer.

这篇关于PreferenceFragmentCompat 需要设置preferenceTheme的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆