使用Intent打开Android首选项进行编辑
是否可以使用 Intent 在 PreferenceActivity 中打开首选项?例如,我使用 OnPreferenceChangeListener 来验证应用程序中的设置,而不是简单地显示错误消息,我希望在出现无效值时将用户发送回编辑屏幕。进入。
Intent可以打开编辑屏幕吗?如果没有,还有其他解决方案吗?
编辑
澄清一下,我并不是在尝试访问 Android 设备设置。我使用 PreferenceActivity
来显示一组自定义首选项,并希望创建一个允许用户修改特定首选项的 Intent。从用户的角度来看,他们会:
- 单击首选项
- 输入一个值
- 如果该值无效,则会显示一条消息
- 用户点击“确定”
- 应用返回到用户可以输入值的位置(返回到步骤 2)
- 如果该值有效,则保存该值
当用户单击“确定”时,应用程序将立即返回到可以输入值的点,并且不需要用户再次单击首选项。
Possible Duplicate:
How to open or simulate a click on a android Preference, which was created with XML, from code programatically?
Is it possible to use an Intent to open a Preference in a PreferenceActivity? For example, I'm using an OnPreferenceChangeListener
to validate settings in an application, and rather than simply displaying an error message, I'd like to send the user back to the editing screen when an invalid value is entered.
Can an Intent open the editing screen? If not, is there another solution?
EDIT
Just to clarify, I'm not trying to access the Android device settings. I'm using a PreferenceActivity
to display a custom set of preferences and want to create an Intent that allows the user to modify a specific preference. From the user's perspective, they would:
- Click on the preference
- Enter a value
- If the value is invalid, a message is displayed
- The user clicks "Ok"
- The app returns to the point where the user can enter a value (returns to step 2)
- If the value is valid, it is saved
When the user clicks ok, the app would immediately return to the point where a value can be entered, and does not require the user to click on the preference again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您指的是 Android 设置。您可以创建一个新的意图,传入
“android.settings.SETTINGS”
:编辑:
现在我知道您正在使用PreferenceActivity ,您应该能够重写 onNewIntent(...) 方法来处理自定义 Intents(您可以解压 Intent 以查看目标首选项是什么)。从这里,您可以通过编程方式打开正确的首选项。
I'm assuming you are referring to the Android Settings. You can create a new Intent, passing in
"android.settings.SETTINGS"
:Edit:
Now that I understand that you are using a PreferenceActivity, you should be able to override the onNewIntent(...) method to handle custom Intents (you can unpack the intent to see what the target preference is). From here, you can programmatically open the correct preference.