添加一个看起来像在本机应用程序中的设置页面 [英] Add a settings page looking like in native app

查看:34
本文介绍了添加一个看起来像在本机应用程序中的设置页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建看起来像本机平台上的设置的设置页面(例如,Android 上带有 xml 的 PreferenceActivity/Fragment).

我习惯于通过在 Android 上创建简单的首选项 xml 来设计设置页面,该 xml 可以完美地处理基本设置,但是我无法在 Xamarin.Forms 中找到类似的机制,它可以对所有平台本机执行相同的操作(使用gui 部分).我只找到了 SettingsPlugin,它可以处理通过所有应用程序的共享代码创建和访问设置!".

I would like to create settings page which would look like the settings on native platform (eg. PreferenceActivity/Fragment with xml on Android).

I am used to design the settings page by creating simple preference xml on Android which handles the basic settings flawlessly, however I am unable to find the similar mechanism in Xamarin.Forms which would do the same thing for all platforms natively (with the gui part). I just only found the SettingsPlugin which handles "Create and access settings from shared code across all of your apps!".

https://github.com/jamesmontemagno/SettingsPlugin

I would really appreciate any recommendation on designing the settings pages.

解决方案

You can use a TableView, which is an original Xamarin Forms User interface (without any plugin). If you set his Intent="Settings" , you can display a nice list of configuration settings like SwitchCell, EntryCell, or a CustomCell.

Displaying these elements depend on the operating system and on the version of it. So it looks and feels different on f.e. Android 4.4 and different on Android 8.

For example:

<TableView Intent="Settings">
    <TableRoot>
        <TableSection Title="My settings">
            <EntryCell Label="Name:" Placeholder="Enter Your First Name Here"/>
            <SwitchCell Text="Show my name" On="true"/>
            <SwitchCell Text="Update app automatically"/>
        </TableSection>
    </TableRoot>
</TableView>

Which will render something (not exactly that) like this: {source of img}

这篇关于添加一个看起来像在本机应用程序中的设置页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆