I checked different options that are available in PreferenceScreen (eg. CheckBoxPreference, EditTextPreference, etc.) but non of them give me the possiblity to obtain a simple dialog with just 2 buttons. I would like to use it to implement a basic “Yes, reset my app” / “Cancel” features. How to make this preference option easily?
Its tricky check this answer.
Well I've implemented EditText Preference which shows 2 buttons ok and cancel but in middle there is Edittext.
Related
I would like a setting in preferences that allows the user to create a password. The perfect example is in the Play Store. In settings you click on Password and a dialog box pops up with an EditText field with a password field that hides the characters. How would you do that?
I'm pretty sure this is not EditTextPreference. Is this a custom preference? How would you make this? Can I get a sample for the XML part of it?
I'm pretty sure this is not EditText preference
EditTextPreference would work. Quoting the documentation:
This EditText can be modified either programmatically via getEditText(), or through XML by setting any EditText attributes on the EditTextPreference.
So adding android:password="true" as part of your preference XML should work.
That being said, you are certainly welcome to create your own custom DialogPreference for this.
Using intents
In some cases, you might want a preference item to open a different activity instead of a settings screen, such as a web browser to view a web page. To invoke an Intent when the user selects a preference item
it's available at android guide, check this link
http://developer.android.com/guide/topics/ui/settings.html#Intents
In my application I currently have an xml layout that is re-used to enter information 6 times (these are turns in a game). This works fine. At the end of the round I present a screen that has a summary of each turn. I want to implement a button beside each turn to "edit" that turn. There are 3 possible things that can be edited. Ideally an alert dialog or something like a "popup" would be idea for this.
Would I be best off to have 3 buttons per "turn" for editing or is there a way to do this with a popup?
Thanks for your input on this matter.
You could list each turn and it's information with a single edit button next to each. When the edit button is pressed, create a new activity (intent) that prompts for all three pieces of data.
You have several options (and probably more I'm not thinking about). If these are in a ListView (or even if not) you could use a ContextMenu. You could have options in here to change the selected item or others. This would show a popup when the user long clicks the item
A PopupMenu can give you a similar effect that can pop up a list of options when the user clicks on a Button. Note that this requires API >= 11
You also could use an AlertDialog, as you mentioned. But just from what little I know about what you are trying to do I'm not sure this is what you would want.
Again, I don't know enough details about what you have or want but I would say that one of the first two options would suit you best. As far as one Button or multiple Buttons, that depends on the layout that will work best for your app, I suppose. You certainly could have one "Edit" Button which uses something like a PopupMenu and allows the user to choose what to edit. I hope this helped a little.
In my Preference activity, say I have two checkboxpreference. If I select the first one, the second one is enabled, but if I deselect the first one, the second one is disabled.
My question is, if the first one is deselected and someone clicks the disabled second preference (it's greyed out), is it possible to attach a hint to it when disabled to tell the user that they must first select the above preference in order to enable the second one?
I looked in the Preferences API, but could not find anything to match this requirement.
Any tips?
Thanks!
Use the preference's summary as your hint. This will provide some text below the checkbox and its title in smaller print.
By xml:
http://developer.android.com/reference/android/preference/Preference.html#attr_android:summary
By code:
http://developer.android.com/reference/android/preference/Preference.html#setSummary(int)
I have no idea how to achieve this, and don't know if it's achievable or not.
I have a sharedPreference value I set via my android app like this
menu button -> settings -> listPreference (a 1 digit value is set this way, among 3 values!!!)
I would however like to be able to set this value without entering the settings menu first, because it is changed often. Im thinking a button should take me directly to the listPreference dialog box like this!
Button -> listPreference
Is is possible to omit the settings menu like this?
Thanks
I asked somthing similar some time back. There is no quick solution but I have a coded up custom solution in the answer to this question
I have a preference that represents some complex notion.
I'd like to explain it, and the explanation is a bit long.
When I add the explanation to the summary of the preference it gets cut off.
Is there a standard for Android having long summary/description/explanation?
Thank you.
You could create your own preference widget: http://developer.android.com/reference/android/preference/Preference.html#attr_android:widgetLayout
I couldn't find any standard for long settings explanations.
My solution
I set the summary to be the value chosen by the preference and added a dialog with a long message to explain the chosen setting when it is chosen.
This kind of keeps the settings UI standard without the need to custom the standard preference layouts.
Material design says that you should make the preference open a separate screen that includes the description:
Settings that require longer explanations may add a description on a second screen.
Underneath the label, show the status text of the switch as "On" or "Off.”
Add the switch itself and a longer description to a second screen.
For an example of this, go to Settings -> Accessibility -> Magnification Gestures.