功能與 API

Android 16 為開發人員推出了強大的新功能和 API。以下各節會簡要說明這些功能,協助您開始使用相關 API。

如需新增、修改及移除 API 的詳細清單,請參閱 API 差異比較表。如要進一步瞭解新的 API,請參閱 Android API 參考資料 - 新的 API 會醒目顯示,以利於查看。

此外,也請查看平台變更可能對應用程式造成的影響。詳情請參閱下列頁面:

核心功能

Android 包含可擴充 Android 系統核心功能的新 API。

2025 年將發布兩項 Android API

  • 此预览版适用于 Android 的下一个主要版本,计划于 2025 年第 2 季度发布。此版本与我们过去的所有 API 版本类似,我们可以进行计划性的行为更改,这些更改通常与 targetSdkVersion 相关联。
  • 我们计划提前一个季度(2021 年第 2 季度,而非之前的第 3 季度)发布主要版本,以便更好地与整个生态系统中的设备发布时间表保持一致,让更多设备能够更早地搭载 Android 主要版本。由于主要版本将于第 2 季度发布,因此您需要比往年提前几个月进行年度兼容性测试,以确保您的应用已做好准备。
  • 我们计划在 2025 年第 4 季度再发布一次,届时还将推出新的开发者 API。2025 年只有第二季度的主要版本包含可能影响应用的计划行为变更。

除了新的开发者 API 之外,第 4 季度次要版本还将包含功能更新、优化和 bug 修复;其中不会包含任何会影响应用的行为变更。

2025 年 Android 版本的时间轴视图,请注意,25Q2 版本是一个主要版本,25Q4 版本是一个次要版本。

我们将继续每季度发布 Android 版本。在 API 版本之间,第 1 季度和第 3 季度的更新将提供增量更新,以帮助确保持续提供高质量的服务。我们正积极与设备合作伙伴合作,将 Q2 版本推广到尽可能多的设备。

在主要版本和次要版本中使用新 API

目前,使用 SDK_INT 常量与 VERSION_CODES 结合使用,即可通过检查 API 级别来保护代码块。我们将继续支持主要 Android 版本。

if (SDK_INT >= VERSION_CODES.BAKLAVA) {
  // Use APIs introduced in Android 16
}

新的 SDK_INT_FULL 常量可用于针对主要版本和次要版本进行 API 检查,并使用新的 VERSION_CODES_FULL 枚举。

if (SDK_INT_FULL >= VERSION_CODES_FULL.[MAJOR or MINOR RELEASE]) {
  // Use APIs introduced in a major or minor release
}

您还可以使用 Build.getMinorSdkVersion() 方法仅获取 SDK 次要版本。

val minorSdkVersion = Build.getMinorSdkVersion(VERSION_CODES_FULL.BAKLAVA)

这些 API 尚未最终确定,可能会发生变化,因此如果您有任何疑虑,请向我们发送反馈

使用者體驗和系統 UI

Android 16 可讓應用程式開發人員和使用者進一步控管及彈性設定裝置,以符合自身需求。

以進度為主的通知

Android 16 推出以進度為主的通知,協助使用者順暢追蹤使用者啟動的端對端歷程。

Notification.ProgressStyle 是一種新的通知樣式,可讓您建立以進度為主的通知。主要用途包括共乘、外送和導航。在 Notification.ProgressStyle 類別中,您可以使用區隔,表示使用者歷程中的狀態和里程碑。

To learn more, see the Progress-centric notifications documentation page.

锁屏上显示的以进度为中心的通知。
在通知栏中显示的以进度为中心的通知。

預測返回更新

Android 16 adds new APIs to help you enable predictive back system animations in gesture navigation such as the back-to-home animation. Registering the onBackInvokedCallback with the new PRIORITY_SYSTEM_NAVIGATION_OBSERVER allows your app to receive the regular onBackInvoked call whenever the system handles a back navigation without impacting the normal back navigation flow.

Android 16 additionally adds the finishAndRemoveTaskCallback() and moveTaskToBackCallback. By registering these callbacks with the OnBackInvokedDispatcher, the system can trigger specific behaviors and play corresponding ahead-of-time animations when the back gesture is invoked.

更豐富的觸覺回饋

Android has exposed control over the haptic actuator ever since its inception.

Android 11 added support for more complex haptic effects that more advanced actuators could support through VibrationEffect.Compositions of device-defined semantic primitives.

Android 16 adds haptic APIs that let apps define the amplitude and frequency curves of a haptic effect while abstracting away differences between device capabilities.

開發人員工作效率和工具

我們致力於改善您的工作效率,因此大部分工作都圍繞在 Android StudioJetpack ComposeAndroid Jetpack 程式庫等工具。此外,我們也持續尋找平台上的各種方法,協助您實現願景。

動態桌布的內容處理方式

在 Android 16 中,动态壁纸框架将获得一个新的 content API,以应对由用户驱动的动态壁纸带来的挑战。目前,包含用户提供的内容的实时壁纸需要复杂的服务专用实现。Android 16 引入了 WallpaperDescriptionWallpaperInstance。借助 WallpaperDescription,您可以识别同一服务中的动态壁纸的不同实例。例如,如果某张壁纸同时在主屏幕和锁定屏幕上显示,则这两种情况下显示的内容可能各不相同。壁纸选择器和 WallpaperManager 会使用此元数据更好地向用户呈现壁纸,从而简化创建多样化个性化动态壁纸体验的过程。

效能和電池

Android 16 推出多項 API,可協助您收集應用程式的深入分析資訊。

系統觸發的剖析

ProfilingManager was added in Android 15, giving apps the ability to request profiling data collection using Perfetto on public devices in the field. However, since this profiling must be started from the app, critical flows such as startups or ANRs would be difficult or impossible for apps to capture.

To help with this, Android 16 introduces system-triggered profiling to ProfilingManager. Apps can register interest in receiving traces for certain triggers such as cold start reportFullyDrawn or ANRs, and then the system starts and stops a trace on the app's behalf. After the trace completes, the results are delivered to the app's data directory.

ApplicationStartInfo 中的啟動元件

ApplicationStartInfo was added in Android 15, allowing an app to see reasons for process start, start type, start times, throttling, and other useful diagnostic data. Android 16 adds getStartComponent() to distinguish what component type triggered the start, which can be helpful for optimizing the startup flow of your app.

更深入瞭解工作

The JobScheduler#getPendingJobReason() API returns a reason why a job might be pending. However, a job might be pending for multiple reasons.

In Android 16, we are introducing a new API JobScheduler#getPendingJobReasons(int jobId), which returns multiple reasons why a job is pending, due to both explicit constraints set by the developer and implicit constraints set by the system.

We're also introducing JobScheduler#getPendingJobReasonsHistory(int jobId), which returns a list of the most recent constraint changes.

We recommend using the API to help you debug why your jobs may not be executing, especially if you're seeing reduced success rates of certain tasks or have bugs around latency of certain job completion. For example, updating widgets in the background failed to occur or prefetch job failed to be called prior to app start.

This can also better help you understand if certain jobs are not completing due to system defined constraints versus explicitly set constraints.

自動調整刷新率

Android 15 中引入的自适应刷新率 (ARR) 可让受支持硬件上的显示屏刷新率使用离散的 VSync 步长来适应内容帧速率。这不仅降低了功耗,还无需进行可能导致卡顿的模式切换。

Android 16 引入了 hasArrSupport()getSuggestedFrameRate(int),同时恢复了 getSupportedRefreshRates(),以便您的应用更轻松地利用 ARR。RecyclerView 1.4从快速滑动或平滑滚动中稳定下来时会在内部支持 ARR,我们将继续努力,将 ARR 支持添加到更多 Jetpack 库中。这篇帧速率文章介绍了许多可用于设置帧速率的 API,以便您的应用可以直接使用 ARR。

ADPF 中的 Headroom API

SystemHealthManager 引入了 getCpuHeadroomgetGpuHeadroom API,旨在为游戏和资源密集型应用提供可用 CPU 和 GPU 资源的估算值。通过这些方法,您可以评估应用或游戏如何以最佳方式改善系统运行状况,尤其是在与用于检测热节流的其他 Android 动态性能框架 (ADPF) API 搭配使用时。

在受支持的设备上使用 CpuHeadroomParamsGpuHeadroomParams,您可以自定义用于计算余量的时间范围,并在平均资源可用性或最低资源可用性之间进行选择。这有助于您相应地减少 CPU 或 GPU 资源用量,从而提升用户体验并延长电池续航时间。

無障礙設定

Android 16 新增了無障礙 API 和功能,可協助您為所有使用者提供應用程式。

改良的無障礙 API

Android 16 添加了其他 API 来增强界面语义,这有助于为依赖于无障碍服务(例如 TalkBack)的用户提高一致性。

为文字添加轮廓,以最大限度地提高文字对比度

视力较低的用户对对比度的敏感度通常较低,因此很难将对象与背景区分开来。为了帮助这些用户,Android 16 引入了轮廓文本,取代了高对比度文本,后者会在文本周围绘制较大的对比度区域,以大大提高可辨性。

Android 16 包含新的 AccessibilityManager API,可让您的应用检查注册监听器,以查看此模式是否已启用。这主要适用于 Compose 等界面工具包,以提供类似的视觉体验。如果您维护界面工具包库,或者您的应用执行绕过 android.text.Layout 类的自定义文本渲染,则可以使用此方法来了解何时启用轮廓文本。

Android 16 推出新的轮廓文本无障碍功能前后,对比度更高的文本

向 TtsSpan 添加了时长

Android 16 使用 TYPE_DURATION 扩展了 TtsSpan,其中包含 ARG_HOURSARG_MINUTESARG_SECONDS。这样,您就可以直接为时长添加注释,确保通过 TalkBack 等服务获得准确且一致的文本转语音输出。

支持具有多个标签的元素

Android 目前允许界面元素从其他元素派生其无障碍功能标签,现在还支持关联多个标签,这是 Web 内容中常见的情况。通过在 AccessibilityNodeInfo 中引入基于列表的 API,Android 可以直接支持这些多标签关系。在进行这项更改的过程中,我们已弃用 AccessibilityNodeInfo#setLabeledBy#getLabeledBy,改用 #addLabeledBy#removeLabeledBy#getLabeledByList

改进了对可展开元素的支持

Android 16 添加了无障碍功能 API,可让您传达互动元素(例如菜单和展开式列表)的展开或收起状态。通过使用 setExpandedState 设置展开状态,并使用 CONTENT_CHANGE_TYPE_EXPANDED 内容更改类型调度 TYPE_WINDOW_CONTENT_CHANGED AccessibilityEvents,您可以确保 TalkBack 等屏幕阅读器会读出状态更改,从而提供更直观、更包容的用户体验。

不确定进度条

Android 16 添加了 RANGE_TYPE_INDETERMINATE,让您可以为确定性和不确定性 ProgressBar 微件公开 RangeInfo,从而让 TalkBack 等服务能够更一致地为进度指示器提供反馈。

三态复选框

Android 16 中的新 AccessibilityNodeInfo getCheckedsetChecked(int) 方法现在除了“已选中”和“未选中”之外,还支持“部分选中”状态。此字段取代了已废弃的布尔值 isCheckedsetChecked(boolean)

补充说明

如果无障碍服务提供关于 ViewGroup 的说明,则会将来自其子视图的内容标签合并在一起。如果您为 ViewGroup 提供 contentDescription,无障碍服务会假定您还要覆盖不可聚焦的子视图的说明。如果您想为下拉菜单等内容添加标签(例如“字体系列”),同时保留当前的无障碍功能选择(例如“Roboto”),这可能会造成问题。Android 16 添加了 setSupplementalDescription,以便您提供用于提供 ViewGroup 相关信息的文本,而不会覆盖其子项中的信息。

必填表单字段

Android 16 向 AccessibilityNodeInfo 添加了 setFieldRequired,以便应用可以告知无障碍服务需要输入表单字段。对于填写各种类型表单的用户而言,这是一个重要的场景,即使是简单的必填条款及条件复选框,也能帮助用户始终如一地识别必填字段并在必填字段之间快速导航。

使用 LE Audio 助聽器時,將手機設為語音通話的麥克風輸入裝置

Android 16 adds the capability for users of LE Audio hearing aids to switch between the built-in microphones on the hearing aids and the microphone on their phone for voice calls. This can be helpful in noisy environments or other situations where the hearing aid's microphones might not perform well.

控制 LEA 助聽器的環境音量

Android 16 新增了一项功能,可让 LE Audio 助听器用户调节助听器麦克风接收的环境声音的音量。在背景噪音过大或过小的情况下,这可能会很有用。

相機

Android 16 強化了對專業相機使用者的支援,可進行混合式自動曝光,並精確調整色溫和色調。新的夜間模式指標可協助應用程式瞭解何時該切換至夜間模式攝影機工作階段,以及何時該切換回來。新的 Intent 動作可讓您更輕鬆地拍攝動態相片,此外,我們也持續改良 Ultra HDR 相片,支援 HEIC 編碼和 ISO 21496-1 草案標準的新參數。

混合式自動曝光

Android 16 向 Camera2 添加了新的混合自动曝光模式,让您可以手动控制曝光的特定方面,同时让自动曝光 (AE) 算法处理其余部分。您可以控制 ISO + AE曝光时间 + AE,与当前方法(您要么完全手动控制,要么完全依赖自动曝光)相比,可提供更大的灵活性。

fun setISOPriority() {
    // ... (Your existing code before the snippet) ...

    val availablePriorityModes = mStaticInfo.characteristics.get(
        CameraCharacteristics.CONTROL_AE_AVAILABLE_PRIORITY_MODES
    )

    // ... (Your existing code between the snippets) ...

    // Turn on AE mode to set priority mode
    reqBuilder.set(
        CaptureRequest.CONTROL_AE_MODE,
        CameraMetadata.CONTROL_AE_MODE_ON
    )
    reqBuilder.set(
        CaptureRequest.CONTROL_AE_PRIORITY_MODE,
        CameraMetadata.CONTROL_AE_PRIORITY_MODE_SENSOR_SENSITIVITY_PRIORITY
    )
    reqBuilder.set(
        CaptureRequest.SENSOR_SENSITIVITY,
        TEST_SENSITIVITY_VALUE
    )
    val request: CaptureRequest = reqBuilder.build()

    // ... (Your existing code after the snippet) ...
}

精確調整色溫和色調

Android 16 增加了对相机的精细色温和色调调整的支持,以更好地支持专业视频录制应用。在较低版本的 Android 中,您可以通过 CONTROL_AWB_MODE 控制白平衡设置,其中包含仅限于预设列表的选项,例如白炽灯多云黄昏COLOR_CORRECTION_MODE_CCT 可让您使用 COLOR_CORRECTION_COLOR_TEMPERATURECOLOR_CORRECTION_COLOR_TINT 根据相关色温精确调整白平衡。

fun setCCT() {
    // ... (Your existing code before this point) ...

    val colorTemperatureRange: Range<Int> =
        mStaticInfo.characteristics[CameraCharacteristics.COLOR_CORRECTION_COLOR_TEMPERATURE_RANGE]

    // Set to manual mode to enable CCT mode
    reqBuilder[CaptureRequest.CONTROL_AWB_MODE] = CameraMetadata.CONTROL_AWB_MODE_OFF
    reqBuilder[CaptureRequest.COLOR_CORRECTION_MODE] = CameraMetadata.COLOR_CORRECTION_MODE_CCT
    reqBuilder[CaptureRequest.COLOR_CORRECTION_COLOR_TEMPERATURE] = 5000
    reqBuilder[CaptureRequest.COLOR_CORRECTION_COLOR_TINT] = 30

    val request: CaptureRequest = reqBuilder.build()

    // ... (Your existing code after this point) ...
}

以下示例展示了应用不同色温和色调调整后的照片效果:

未应用色温或色调调整的原始图片。
将色温调整为 3000 的图片。
将色温调整为 7000 的图片。


将色调级别降低 50 的图片。
色调级别提高了 50 的图片。

相機夜間模式場景偵測

To help your app know when to switch to and from a night mode camera session, Android 16 adds EXTENSION_NIGHT_MODE_INDICATOR. If supported, it's available in the CaptureResult within Camera2.

This is the API we briefly mentioned as coming soon in the How Instagram enabled users to take stunning low light photos blog post. That post is a practical guide on how to implement night mode together with a case study that links higher-quality in-app night mode photos with an increase in the number of photos shared from the in-app camera.

動態相片拍攝意圖動作

Android 16 添加了标准 intent 操作 ACTION_MOTION_PHOTO_CAPTUREACTION_MOTION_PHOTO_CAPTURE_SECURE,用于请求相机应用拍摄动态照片并将其返回。

您必须传递额外的 EXTRA_OUTPUT 来控制将图片写入的位置,或者通过 Intent.setClipData(ClipData) 传递 Uri。如果您未设置 ClipData,系统会在调用 Context.startActivity(Intent) 时将其复制到该位置。

动态照片示例,显示静态图片和动态播放画面。

UltraHDR 圖片強化功能

An illustration of Standard Dynamic Range (SDR) versus High Dynamic Range (HDR) image quality.

Android 16 continues our work to deliver dazzling image quality with UltraHDR images. It adds support for UltraHDR images in the HEIC file format. These images will get ImageFormat type HEIC_ULTRAHDR and will contain an embedded gainmap similar to the existing UltraHDR JPEG format. We're working on AVIF support for UltraHDR as well, so stay tuned.

In addition, Android 16 implements additional parameters in UltraHDR from the ISO 21496-1 draft standard, including the ability to get and set the colorspace that gainmap math should be applied in, as well as support for HDR encoded base images with SDR gainmaps.

圖形

Android 16 包含最新的圖像改善功能,例如使用 AGSL 自訂圖像效果。

使用 AGSL 製作自訂圖像效果

Android 16 添加了 RuntimeColorFilterRuntimeXfermode,让您可以创作阈值、Sepia 和 Hue Saturation 等复杂效果,并将其应用于绘制调用。从 Android 13 开始,您可以使用 AGSL 创建扩展 Shader 的自定义 RuntimeShader。新 API 反映了这一点,添加了由 AGSL 驱动的 RuntimeColorFilter(用于扩展 ColorFilter)和 Xfermode 效果,让您可以在源像素和目标像素之间实现基于 AGSL 的自定义合成和混合。

private val thresholdEffectString = """
    uniform half threshold;

    half4 main(half4 c) {
        half luminosity = dot(c.rgb, half3(0.2126, 0.7152, 0.0722));
        half bw = step(threshold, luminosity);
        return bw.xxx1 * c.a;
    }"""

fun setCustomColorFilter(paint: Paint) {
   val filter = RuntimeColorFilter(thresholdEffectString)
   filter.setFloatUniform(0.5);
   paint.colorFilter = filter
}

連線能力

Android 16 更新了平台,讓應用程式能使用通訊和無線技術的最新進展。

安全再升級的測距功能

Android 16 adds support for robust security features in Wi-Fi location on supported devices with Wi-Fi 6's 802.11az, allowing apps to combine the higher accuracy, greater scalability, and dynamic scheduling of the protocol with security enhancements including AES-256-based encryption and protection against MITM attacks. This allows it to be used more safely in proximity use cases, such as unlocking a laptop or a vehicle door. 802.11az is integrated with the Wi-Fi 6 standard, leveraging its infrastructure and capabilities for wider adoption and easier deployment.

一般測距 API

Android 16 includes the new RangingManager, which provides ways to determine the distance and angle on supported hardware between the local device and a remote device. RangingManager supports the usage of a variety of ranging technologies such as BLE channel sounding, BLE RSSI-based ranging, Ultra Wideband, and Wi-Fi round trip time.

隨附裝置管理工具裝置狀態

在 Android 16 中,我們推出了新的 API,用於繫結隨附應用程式服務。當 BLE 在範圍內且已連上藍牙時,服務就會繫結;當 BLE 超出範圍或藍牙已中斷連線時,服務就會解除繫結。應用程式會根據各種 DevicePresenceEvent 接收新的 'onDevicePresenceEvent()' 回呼。如需更多詳細資訊,請參閱「startObservingDevicePresence(ObservingDevicePresenceRequest)」一文。

媒體

Android 16 包含多項功能,可提升媒體體驗。

相片挑選工具改良功能

照片选择器为用户提供了一种安全的内置授权方式,让用户可以向应用授予对本地存储空间和云端存储空间中所选图片和视频的访问权限,而不是对整个媒体库的访问权限。通过 Google 系统更新Google Play 服务组合使用模块化系统组件,该工具向后支持到 Android 4.4(API 级别 19)。只需几行代码即可与相关的 Android Jetpack 库集成。

Android 16 对照片选择器进行了以下改进:

  • 嵌入式照片选择器新 API,可让应用将照片选择器嵌入其视图层次结构中。这样,它就感觉像是应用中更为集成的一部分,同时仍可利用进程隔离功能,让用户能够选择媒体,而无需应用拥有过于宽泛的权限。为了最大限度地提高跨平台版本的兼容性并简化集成,如果您想集成嵌入式照片选择器,则需要使用即将推出的 Android Jetpack 库。
  • 照片选择器中的云搜索新的 API 可让 Android 照片选择器从云端媒体提供商中进行搜索。照片选择器中的搜索功能即将推出。

進階專業影片

Android 16 introduces support for the Advanced Professional Video (APV) codec which is designed to be used for professional level high quality video recording and post production.

The APV codec standard has the following features:

  • Perceptually lossless video quality (close to raw video quality)
  • Low complexity and high throughput intra-frame-only coding (without pixel domain prediction) to better support editing workflows
  • Support for high bit-rate range up to a few Gbps for 2K, 4K and 8K resolution content, enabled by a lightweight entropy coding scheme
  • Frame tiling for immersive content and for enabling parallel encoding and decoding
  • Support for various chroma sampling formats and bit-depths
  • Support for multiple decoding and re-encoding without severe visual quality degradation
  • Support multi-view video and auxiliary video like depth, alpha, and preview
  • Support for HDR10/10+ and user-defined metadata

A reference implementation of APV is provided through the OpenAPV project. Android 16 will implement support for the APV 422-10 Profile that provides YUV 422 color sampling along with 10-bit encoding and for target bitrates of up to 2Gbps.

隱私權

Android 16 包含多項功能,可協助應用程式開發人員保護使用者隱私權。

健康資料同步更新

Health Connect 添加了 ACTIVITY_INTENSITY,这是一种根据世界卫生组织关于中等强度和剧烈强度活动的指南定义的数据类型。每个记录都需要提供开始时间、结束时间以及活动强度(中等或剧烈)。

Health Connect 还包含支持医疗记录的更新版 API。这样一来,应用便可在征得用户明确同意的情况下,读取和写入 FHIR 格式的医疗记录。

Android 版 Privacy Sandbox

Android 16 incorporates the latest version of the Privacy Sandbox on Android, part of our ongoing work to develop technologies where users know their privacy is protected. Our website has more about the Privacy Sandbox on Android developer beta program to help you get started. Check out the SDK Runtime which allows SDKs to run in a dedicated runtime environment separate from the app they are serving, providing stronger safeguards around user data collection and sharing.

安全性

Android 16 包含多項功能,可協助您提升應用程式的安全性及保護應用程式資料。

金鑰共用 API

Android 16 新增了 API,可支援與其他應用程式共用 Android KeyStore 金鑰的存取權。新的 KeyStoreManager 類別支援應用程式 uid 授予撤銷金鑰存取權,並包含可讓應用程式存取共用金鑰的 API。

裝置板型規格

Android 16 可讓應用程式充分運用 Android 的板型規格。

電視的標準化影像和音訊品質架構

The new MediaQuality package in Android 16 exposes a set of standardized APIs for access to audio and picture profiles and hardware-related settings. This allows streaming apps to query profiles and apply them to media dynamically:

  • Movies mastered with a wider dynamic range require greater color accuracy to see subtle details in shadows and adjust to ambient light, so a profile that prefers color accuracy over brightness may be appropriate.
  • Live sporting events are often mastered with a narrow dynamic range, but are often watched in daylight, so a profile that preferences brightness over color accuracy can give better results.
  • Fully interactive content wants minimal processing to reduce latency, and wants higher frame rates, which is why many TV's ship with a game profile.

The API allows apps to switch between profiles and users to enjoy tuning supported TVs to best suit their content.

國際化

Android 16 新增多項功能,在裝置使用不同語言時,可提升使用者體驗。

直書文字

Android 16 添加了对垂直渲染和测量文本的低级支持,以便为库开发者提供基本的垂直书写支持。这对于日语等通常使用竖向书写系统的语言特别有用。Paint 类中添加了一个新标志 VERTICAL_TEXT_FLAG。使用 Paint.setFlags 设置此标志后,Paint 的文本测量 API 将报告垂直进度,而不是水平进度,并且 Canvas 将垂直绘制文本。

val text = "「春は、曙。」"
Box(
    Modifier.padding(innerPadding).background(Color.White).fillMaxSize().drawWithContent {
        drawIntoCanvas { canvas ->
            val paint = Paint().apply { textSize = 64.sp.toPx() }
            // Draw text vertically
            paint.flags = paint.flags or VERTICAL_TEXT_FLAG
            val height = paint.measureText(text)
            canvas.nativeCanvas.drawText(
                text,
                0,
                text.length,
                size.width / 2,
                (size.height - height) / 2,
                paint
            )
        }
    }
) {}

自訂計量系統

用户现在可以在“设置”中的地区偏好设置中自定义测量系统。用户偏好设置包含在语言区域代码中,因此您可以在 ACTION_LOCALE_CHANGED 上注册 BroadcastReceiver,以便在地区偏好设置发生更改时处理语言区域配置更改。

使用格式设置程序有助于提供符合当地体验的服务。例如,对于将手机设置为英语(丹麦)或将手机设置为英语(美国)并将公制作为首选测量系统的用户,“0.5 in”的英语(美国)对应于“12,7 mm”。

如需找到这些设置,请打开“设置”应用,然后依次前往系统 > 语言和地区