首选项 - 使用媒体文件、图像
我是一名新开发人员,所以我的问题可能太基本了。 我寻找定义声音偏好的例子。例如,用户可以选择启动应用程序的声音类型。可以有这样一个RingtonPreference小部件,这样用户就可以选择声音。 据我所知,首选项支持基本类型:布尔型、字符串、浮点型、长整型和整数。设计首选项的最佳方式是什么:将声音名称(字符串)、资源类中的文件地址(整数)或其他方式存储在entryValues中。 请提供一个简短的代码示例。 提前致谢!
首先感谢您快速而详细的回答! 我想排列声音列表:必须有一个“无”,包含文件夹“raw”的声音列表,从不同位置添加新声音的选项以及两个按钮:“设置”和“取消”。当用户触摸列表中的一项时 - 声音开始播放。 提供 android 库的标准小部件有一个小问题。 “ListPreference”是不合适的,因为触摸其中一个项目 - 项目被选择并且列表关闭,“没有按钮设置和取消”。 “RingtonPreference”也不合适——我没有成功添加一些东西到列表中。 如何构建自定义首选项布局,即选择的选项将被保存在标准小部件上。请提供一个简短的代码示例。提前致谢!
I’m a new developer, so my question maybe too much basic.
I look for example of defining preferences of sound. User can choose what kind of sound will start an application, for example. There can be such a RingtonPreference widjet, so user can choose a sound.
As I know, preferences support the primitive types: Boolean, string, float, long and integer. What way is the best to design preferences: store in entryValues the names if sounds (strings), the address of files from Resourse class (integer), or other way.
Please provide a short example of code.
Thanks in advance!
First of all thank you for the quick and detailed answer!
I want to arrange list of sounds: there must be one “None”, list of sounds that contains folder “raw”, option to add a new sound from different locations and two buttons: “set” and “cancel”. When user touches one item from the list – sound starts to play.
There is a little problem with standard widget that provide android library. “ListPreference” isn’t appropriate because on touch on one of the items – item is chosen and list closes, “there are not buttons set and cancel”.
“RingtonPreference” isn’t appropriate as well – I didn’t succeed to add something to list.
How is possible to build a custom preference layout and that is options that were chosen will be saved as well as on standard widgets. Please provide a short code example. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为存储资源的最佳方法是使用整数。或者你可以做名字。
我认为整数更可靠。
因此,要使用 SharedPreference ,您需要访问应用程序 SharedPreference
您可能需要创建一个方法将歌曲放入 SharedPreference 中,例如;
I think the best way to store the Resource are by integers. or you could do names.
I think integer is more reliable.
So to use SharedPreference with this you will need to get access to the apps SharedPreference
You will probably want to create a method to put the songs in the SharedPreference such as;