简体   繁体   English

Android - 是否可以专门为每个 ListPreference 条目更改属性?

[英]Android - Is it possible to change a property specifically for each ListPreference entry?

I have an ordinary Android ListPreference defined in my code -我在我的代码中定义了一个普通的 Android ListPreference -

<ListPreference
        android:title="Font"
        android:summary="Choose the font of the reader"
        android:key="fontList"
        android:entries="@array/fonts"
        android:entryValues="@array/fontValues">

    </ListPreference>

It gives a list of a couple of different font types that the user can pick from, nothing special.它提供了用户可以选择的几种不同字体类型的列表,没什么特别的。 What I wondering is, is there a way to set each list item's font to the font that it displays?我想知道的是,有没有办法将每个列表项的字体设置为它显示的字体? This would be a nice feature as it would allow the user to see what they have to pick from before having to test it out.这将是一个很好的功能,因为它允许用户在必须测试之前查看他们必须选择的内容。

I can't see any obvious way of doing it, or at least a way that wouldn't destroy the nice default UI.我看不到任何明显的方法,或者至少不会破坏漂亮的默认 UI 的方法。

Any help would be appreciated.任何帮助,将不胜感激。

The best way to do it would be to extend the ListPreference class and implement your own preference.最好的方法是扩展 ListPreference class 并实现您自己的偏好。 From memory I think you need to override the onCreateDialogView, onBindDialogView, onSetInitialValue and onDialogClosed methods.从 memory 我认为您需要覆盖 onCreateDialogView、onBindDialogView、onSetInitialValue 和 onDialogClosed 方法。 Best place to look is at the List Preference page on developer.android.com最佳查看位置是developer.android.com 上的 List Preference 页面

like he said for fonts u will need custom one.就像他对 fonts 所说的那样,你需要定制一个。 But what I found that there are alot of different default android:theme="@android:style/Theme....." try the once that are available... there are 9-10 of them.但是我发现有很多不同的默认 android:theme="@android:style/Theme....." 尝试一次可用的......其中有 9-10 个。 maybe u will get somewhat closer to what u need that extending your own custom UI.也许你会更接近你需要扩展你自己的自定义 UI 的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM