I'm trying to add an image / icon to certain entries of a ListPreference alongside the text.
I would like achieve this programmatically.
Here's an excerpt of the preferences.xml
<ListPreference
android:key="prefGameMode"
android:title="#string/pref_game_mode"
android:summary="#string/pref_game_mode_desc"
android:defaultValue="fourChallenge"
android:entries="#array/arrGameMode"
android:entryValues="#array/arrGameModeValues"
android:negativeButtonText="#string/cancel" />
...
The goal here is to illustrate that some of the options listed are unavailable/ locked in the current version of the app. However, the code-base is used as a library, so I would like the solution to work via code, rather than xml.
Any ideas how to do this? Thanks.
Preferences already gives you a way to indicate that an option is unavailable: just set enabled properly.
Related
I'm trying to implement SeekBarPreference into my preference XML. I have attempted to use MrBIMC seekbar (https://github.com/MrBIMC/MaterialSeekBarPreference) which mostly worked but due to it being old, there were some issues I had to come up with ugly solutions for.
<SeekBarPreference
android:defaultValue="5"
android:dependency="a_different_preference"
android:key="seekbar_key"
android:max="40"
android:summary="Select your value"
android:title="Seekbar value"
app:iconSpaceReserved="false"
asp:min="1" />
The above code does mostly what I want, except I can't figure out how to add a measurement value.
sample:msbp_measurementUnit="km"
The above is what is used in the MrBIMC library to set a unit after the value, but can't achieve anything similar natively.
Lastly, in my preferences.xml, I get the error "Element SeekBarPreference is not allowed here" which is preventing the IDE from showing me any suggestions to get what I am after.
Edit:
Since asking this, I have learnt that the native seekbarpreference does not seem to have the ability to add a measurement unit after its value... So, how exactly can I create a custom view, that looks and behaves the same, but has the ability to input a measurement unit?
This Stack Overflow question I had found has used a SeekBarPreference as an example of how to make a custom Preference: Creating Custom Preference
In addition to this, in the XML file, you can just add a spinner to seekbar_preference.xml.
Or, an even easier solution (but not really what you want) is to add a separate ListPreference to your preferences.xml file and input the preferred unit of measurement from there.
I've read Android's settings tutorial, and want to use the new "headers" feature in order to accomplish something like the left image. To be exact, I want to have a global "enabled" checkbox, and below it some preference headers surrounded with a category header.
Can I make it be just by using XMLs ?
Yes it is possible by writing your own adapter class that handles headers. I found this nice pretty straightforward example for native settings looking like preference.
It's working on handset but it's not fixed for tablet (app crashes as it tries to use two-pane layout).
I took a look at the preference activity that Android use for settings. i'm looking for something like UISwitch as shown in below image, does Android have one like this.
I can see the nearest control on Android preference settings is "list preference"
There is ToggleButton and CompoundButton (one extends the other).
But those have a different default display widget then what you are looking for. However either could be used along with your own drawable resources to create the "switch" type control that you are after.
But by default no the system does not include a widget that serves this function and looks the way you want it to.
No, In Android its called ToggleButton.
But still it can be developed by extending RadioButton placed in RadioGroup and giving its UI way you wanted.
I have been tired apply a style or a layout to a preference, but it didn't work well.
Could anyone help me with this?
I also find someone say it could be done in listview,But I wanna how to make those blank spaces between two block?
Please, help me with this , it has been puzzled me a long time.Thanks!
You can have a transparent divider between ListItems
android:dividerHeight="10 dip"
You can group your preferences by using PreferenceCategories and PreferenceScreens. If you want a preference to have an icon associated with it, you can use the android:icon attribute on the preference. Are there any specific characteristics of the iPhone settings that you're trying to replicate. You're not going to get your preferences to look exactly like the iPhones setting page, but you can certainly mimic certain characteristics.
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.