TheLettuceMaster
TheLettuceMaster

Reputation: 15734

Create Android preference in settings to set password

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?

Upvotes: 2

Views: 4162

Answers (2)

Abou-Emish
Abou-Emish

Reputation: 2321

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

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006574

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.

Upvotes: 3

Related Questions