简体   繁体   中英

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

I have an ordinary Android ListPreference defined in my code -

<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.

Any help would be appreciated.

The best way to do it would be to extend the ListPreference class and implement your own preference. From memory I think you need to override the onCreateDialogView, onBindDialogView, onSetInitialValue and onDialogClosed methods. Best place to look is at the List Preference page on developer.android.com

like he said for fonts u will need custom one. 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. maybe u will get somewhat closer to what u need that extending your own custom UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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