其他分享
首页 > 其他分享> > android-PreferenceActivity的优点

android-PreferenceActivity的优点

作者:互联网

在我的应用程序中添加“设置”屏幕时,我似乎提出了两种选择:

>使用Android提供的PreferenceActivity
>创建一个标准的活动,以保存所有用户的选择

假设我不介意编写保存首选项的代码(一项相对琐碎的任务),那么使用PreferenceActivity还有什么其他好处?如果有的话,使用标准的Activity可提供有关UI设计的更多灵活性.

解决方法:

您是对的,鉴于所需的视图复杂度(有时不太有用-记住首选项应易于设置),实现PreferenceActivity可能没有意义.这个想法是要提供一个统一的配置屏幕和用户的视觉风格.这样,用户将始终知道他何时进入偏好屏幕.

从文档:

Furthermore, the preferences shown will follow the visual style of system
preferences. It is easy to create a hierarchy of preferences (that can be
shown on multiple screens) via XML. For these reasons, it is recommended
to use this activity (as a superclass) to deal with preferences in applications.

文档说了一些有关膨胀视图的问题,也许您可​​以研究是否可以集成复杂的布局或自定义视图.

标签:preferenceactivity,android
来源: https://codeday.me/bug/20191208/2094638.html