安卓:使用开关preference pre API级别14级别、pre、preference、API

2023-09-03 21:20:10 作者:谎言成双

pre-API级别14没有开关preference。如果我使用preferences.xml创建我的preference屏幕上是有一些方法的API等级来区分?因此,有老版本的复选框,并切换为API 14?

什么是最好的方法是什么?

解决方案   

如果我用preferences.xml创建我的preference屏幕上是有一些方法的API等级来区分?因此,有老版本的复选框,并切换为API 14?

创建一个 RES / XML-V14 / 目录,其中包含一个 preferences.xml 有你开关preference 。创建一个 RES / XML / 目录,其中包含一个 preferences.xml 文件替换开关preference 复选框preference 。 Android将基于应用程序上运行的设备版本加载正确的 preferences.xml 文件的版本。

Pre-API Level 14 there is no switch preference. If I use preferences.xml to create my preference screen is there some way to distinguish between the API levels? So having a check box for old releases and a switch for API 14?

.NET Core 3.0 Preview 3中关于ASP.NET Core的更新内容

What would be the best way?

解决方案

If I use preferences.xml to create my preference screen is there some way to distinguish between the API levels? So having a check box for old releases and a switch for API 14?

Create a res/xml-v14/ directory that contains a preferences.xml that has your SwitchPreference. Create a res/xml/ directory that contains a preferences.xml file that replaces the SwitchPreference with a CheckBoxPreference. Android will load the right preferences.xml file edition based on the device version the app is running on.