Android 16 為開發人員推出強大的新功能和 API。以下各節將摘要說明這些功能,協助您開始使用相關 API。
如需新增、修改及移除 API 的詳細清單,請參閱 API 差異比較表。如要進一步瞭解新的 API,請參閱 Android API 參考資料 - 新的 API 會醒目顯示,以利於查看。此外,您也應查看平台變更可能對應用程式造成的影響。詳情請參閱下列頁面:
核心功能
Android 包含新的 API,可擴充 Android 系統的核心功能。
2025 年將推出兩個 Android API 版本
- 這個預覽版適用於下一個 Android 主要版本,預計於 2025 年第 2 季推出。這個版本與我們過去的所有 API 版本類似,我們可以進行預定的行為變更,這些變更通常與 targetSdkVersion 相關。
- 我們預計將主要版本提前一個季發布 (第 2 季,而非以往的第 3 季),以便與生態系統中的裝置推出時程保持一致,讓更多裝置能盡早取得主要的 Android 版本。由於主要版本將於第 2 季推出,您需要比往年提早幾個月進行年度相容性測試,確保應用程式已準備就緒。
- 我們預計在 2025 年第 4 季推出另一個版本,其中也會納入新的開發人員 API。2025 年唯一會納入可能影響應用程式的行為變更計畫的版本,就是第 2 季主要版本。
除了新的開發人員 API,第 4 季次要版本還會推出功能更新、最佳化和錯誤修正,但不會包含任何會影響應用程式的行為變更。
我們會持續每季發布 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 就提供了对触感反馈致动器的控制。
Android 11 添加了对更复杂的触感反馈效果的支持,更高级的致动器可以通过设备定义的语义基元 VibrationEffect.Compositions 支持这些效果。
Android 16 添加了触感反馈 API,让应用能够定义触感反馈效果的振幅和频率曲线,同时抽象出设备功能之间的差异。
開發人員工作效率和工具
雖然我們為了提高您的工作效率,大部分的工作都集中在 Android Studio、Jetpack Compose 和 Android Jetpack 程式庫等工具上,但我們也一直在尋找平台上的方法,協助您實現願景。
動態桌布的內容處理
在 Android 16 中,动态壁纸框架将获得一个新的 content API,以应对由用户驱动的动态壁纸带来的挑战。目前,包含用户提供的内容的实时壁纸需要复杂的服务专用实现。Android 16 引入了 WallpaperDescription 和 WallpaperInstance。借助 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.
更完善的工作自我檢查
JobScheduler#getPendingJobReason() API 会返回作业可能处于待处理状态的原因。不过,作业处于待处理状态的原因可能有多种。
在 Android 16 中,我们引入了一个新 API JobScheduler#getPendingJobReasons(int jobId),该 API 会返回作业处于待处理状态的多种原因,包括开发者设置的显式约束条件和系统设置的隐式约束条件。
我们还引入了 JobScheduler#getPendingJobReasonsHistory(int jobId),用于返回最新约束条件更改的列表。
我们建议您使用该 API 来调试作业可能无法执行的原因,尤其是在您发现某些任务的成功率降低或某些作业完成延迟存在 bug 时。例如,未能在后台更新微件,或在应用启动之前未能调用预加载作业。
这还有助于您更好地了解某些作业是否因系统定义的约束条件而无法完成,而不是因明确设置的约束条件而无法完成。
自動調整刷新率
Adaptive refresh rate (ARR), introduced in Android 15, enables the display refresh rate on supported hardware to adapt to the content frame rate using discrete VSync steps. This reduces power consumption while eliminating the need for potentially jank-inducing mode-switching.
Android 16 introduces hasArrSupport() and
getSuggestedFrameRate(int) while restoring
getSupportedRefreshRates() to make it easier for your apps to take
advantage of ARR. RecyclerView
1.4 internally supports ARR when it is settling from a fling or
smooth scroll, and we're continuing our work to add ARR
support into more Jetpack libraries. This frame rate article covers
many of the APIs you can use to set the frame rate so that your app can directly
use ARR.
ADPF 中的 Headroom API
SystemHealthManager 引進 getCpuHeadroom 和 getGpuHeadroom API,旨在為遊戲和資源密集型應用程式提供可用 CPU 和 GPU 資源的預估值。這些方法可讓您評估應用程式或遊戲如何最佳化系統健康狀況,尤其是與其他Android 動態效能架構 (ADPF) API 搭配使用時,這些 API 可偵測熱控調節。
在支援的裝置上使用 CpuHeadroomParams 和 GpuHeadroomParams,您可以自訂用於計算預留空間的時間視窗,並選擇平均或最低資源可用性。這麼做可以協助您相應減少 CPU 或 GPU 資源使用量,進而提供更優質的使用者體驗和更長的電池續航力。
無障礙設定
Android 16 新增無障礙 API 和功能,可協助您將應用程式提供給每位使用者。
改良的 Accessibility API
Android 16 新增了其他 API,可強化使用者介面語意,協助依賴無障礙服務 (例如 TalkBack) 的使用者提升一致性。
加外框的文字,可盡可能提高文字對比度
低視力使用者通常對對比敏感度較低,因此很難從背景中辨識物體。為協助這類使用者,Android 16 引進了外框文字,取代高對比文字,這項功能會在文字周圍繪製較大的對比區域,大幅提升易讀性。
Android 16 包含新的 AccessibilityManager API,可讓應用程式檢查或註冊事件監聽器,瞭解是否已啟用此模式。這項功能主要適用於 Compose 等 UI 工具包,可提供類似的視覺體驗。如果您維護 UI 工具包程式庫,或應用程式執行會略過 android.text.Layout 類別的自訂文字算繪作業,則可使用此方法瞭解何時啟用輪廓文字。
新增至 TtsSpan 的時間長度
Android 16 會使用 TYPE_DURATION 擴充 TtsSpan,其中包含 ARG_HOURS、ARG_MINUTES 和 ARG_SECONDS。這可讓您直接註解時間長度,確保 TalkBack 等服務能提供準確且一致的文字轉語音輸出內容。
支援含有多個標籤的元素
Android 目前允許 UI 元素從其他元素衍生無障礙標籤,現在則提供多個標籤的關聯功能,這也是網路內容的常見情境。在 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
getChecked 和 setChecked(int) 方法現在除了支援「已勾選」和「未勾選」之外,也支援「部分勾選」狀態。這會取代已淘汰的布林值 isChecked 和 setChecked(boolean)。
補充說明
無障礙服務說明 ViewGroup 時,會結合其子項檢視畫面的內容標籤。如果您為 ViewGroup 提供 contentDescription,無障礙服務會假設您也要覆寫無法聚焦的子項檢視畫面的說明。如果您想標示下拉式選單 (例如「字型系列」),同時保留現有無障礙選項 (例如「Roboto」),這可能會造成問題。Android 16 新增了 setSupplementalDescription,讓您可以提供文字,提供 ViewGroup 的相關資訊,而不會覆寫其子項的資訊。
必填表單欄位
Android 16 會將 setFieldRequired 新增至 AccessibilityNodeInfo,讓應用程式可向無障礙服務指出表單欄位需要輸入內容。對於填寫各種表單的使用者來說,這都是重要的情境,即使是像條款和條件核取方塊這類簡單的項目,也能協助使用者一貫地識別並快速瀏覽必要欄位。
使用 LEA 助聽器進行語音通話時,將手機設為麥克風輸入裝置
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 adds the capability for users of LE Audio hearing aids to adjust the volume of ambient sound that is picked up by the hearing aid's microphones. This can be helpful in situations where background noise is too loud or too quiet.
相機
Android 16 強化對專業相機使用者的支援,允許混合自動曝光,以及精確調整色溫和色調。新的夜間模式指標可協助應用程式判斷何時切換至夜間模式相機會話群組,以及何時切換回一般模式。新的 Intent 動作可讓您更輕鬆地拍攝動態相片,我們也持續改善 UltraHDR 圖片,支援 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 adds camera support for fine color temperature and tint adjustments
to better support professional video recording applications. In previous Android
versions, you could control white balance settings through
CONTROL_AWB_MODE, which contains options limited to a
preset list, such as Incandescent,
Cloudy, and Twilight. The
COLOR_CORRECTION_MODE_CCT enables the use of
COLOR_CORRECTION_COLOR_TEMPERATURE and
COLOR_CORRECTION_COLOR_TINT for precise adjustments of
white balance based on the correlated color temperature.
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) ...
}
The following examples show how a photo would look after applying different color temperature and tint adjustments:
相機夜間模式場景偵測
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 adds standard Intent actions —
ACTION_MOTION_PHOTO_CAPTURE, and
ACTION_MOTION_PHOTO_CAPTURE_SECURE — which request that
the camera application capture a motion photo and return
it.
You must either pass an extra EXTRA_OUTPUT to control
where the image will be written, or a Uri through
Intent.setClipData(ClipData). If you don't set a
ClipData, it will be copied there for you when calling
Context.startActivity(Intent).
Ultra HDR 圖片強化功能
Android 16 持續致力於透過 UltraHDR 圖片提供令人驚豔的圖像品質。新增對 HEIC 檔案格式中的 UltraHDR 圖片支援。這些圖片會取得 ImageFormat 類型的 HEIC_ULTRAHDR,並包含類似現有 UltraHDR JPEG 格式的內嵌增益圖。我們也正在努力讓 AVIF 支援 UltraHDR,敬請期待。
此外,Android 16 會根據 ISO 21496-1 草稿標準,在 UltraHDR 中實作其他參數,包括取得及設定應套用的增益圖數值空間,以及支援 HDR 編碼的基礎圖片,並使用 SDR 增益圖。
圖形
Android 16 包含最新的圖像功能改善項目,例如使用 AGSL 自訂圖像效果。
使用 AGSL 自訂圖形效果
Android 16 adds RuntimeColorFilter and
RuntimeXfermode, allowing you to author complex effects like
Threshold, Sepia, and Hue Saturation and apply them to draw calls. Since Android
13, you've been able to use AGSL to create custom
RuntimeShaders that extend Shader. The new API
mirrors this, adding an AGSL-powered RuntimeColorFilter that
extends ColorFilter, and a Xfermode effect that
lets you implement AGSL-based custom compositing and blending between source and
destination pixels.
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 新增了對 Wi-Fi 6 的 802.11az 支援裝置 Wi-Fi 位置資訊的強大安全性功能支援,讓應用程式可結合更高的精確度、更大的可擴充性和動態排程的通訊協定,以及 AES-256 加密和防範中間人攻擊的安全性強化功能。這可讓使用者在近距離用途 (例如解鎖筆電或車門) 時,更安全地使用這項功能。802.11az 已整合 Wi-Fi 6 標準,可利用其基礎架構和功能,讓採用率更廣泛,部署作業也更輕鬆。
一般測距 API
Android 16 包含新的 RangingManager,可用於判斷本機裝置與遠端裝置之間的距離和角度,前提是裝置支援硬體。RangingManager 支援各種測距技術,例如 BLE 通道測試、BLE RSSI 測距、超寬頻和 Wi-Fi 往返時間。
隨附裝置管理工具裝置目前狀態
在 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 推出了對進階專業影片 (APV) 轉碼器的支援,該轉碼器專為專業級高品質影片錄製和後製作業而設計。
APV 編碼器標準具有下列功能:
- 感知上無損的影片品質 (接近原始影片品質)
- 低複雜度和高吞吐量的單一影格編碼 (不含像素網域預測),以便更妥善支援編輯工作流程
- 支援高位元速率範圍 (最高可達數 Gbps),適用於 2K、4K 和 8K 解析度的內容,可透過輕量化熵值編碼方案啟用
- 為沉浸式內容和啟用平行編碼/解碼作業的框架平鋪作業
- 支援各種色度取樣格式和位元深度
- 支援多重解碼和重新編碼,且不會嚴重降低視覺品質
- 支援多視角影片和輔助影片,例如深度、alpha 和預覽
- 支援 HDR10/10+ 和使用者定義的中繼資料
OpenAPV 專案提供 APV 的參考實作項目。Android 16 將實作支援 APV 422-10 設定檔,提供 YUV 422 色彩取樣功能,以及 10 位元編碼和最高 2 Gbps 的目標位元率。
隱私權
Android 16 包含多項功能,可協助應用程式開發人員保護使用者隱私。
「健康資料同步」更新
Health Connect 新增了 ACTIVITY_INTENSITY,這是根據世界衛生組織針對中度和劇烈活動制定的規範所定義的資料類型。每個記錄都需要開始時間、結束時間,以及活動強度是屬於中等或劇烈。
Health Connect 也包含支援醫療記錄的更新版 API。這樣一來,應用程式就能在取得使用者的明確同意後,以 FHIR 格式讀取及寫入醫療記錄。
Android 版 Privacy Sandbox
Android 16 中集成了最新版本的 Privacy Sandbox on Android,这是我们持续致力于开发可让用户放心地知道其隐私受到保护的技术的一部分。您可以访问我们的网站,详细了解 Privacy Sandbox on Android 开发者 Beta 版计划,以便顺利上手。不妨了解 SDK 运行时,它可让 SDK 在与其所服务的应用分离的专用运行时环境中运行,从而为用户数据收集和共享提供更强的保护措施。
安全性
Android 16 包含多項功能,可協助您強化應用程式安全性,並保護應用程式資料。
金鑰共用 API
Android 16 adds APIs that support sharing access to
Android Keystore keys with other apps. The new
KeyStoreManager class supports
granting and revoking access to keys
by app uid, and includes an API for apps to access shared
keys.
裝置板型規格
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 adds low-level support for rendering and measuring text vertically to
provide foundational vertical writing support for library developers. This is
particularly useful for languages like Japanese that commonly use vertical
writing systems. A new flag,
VERTICAL_TEXT_FLAG,
has been added to the Paint class. When
this flag is set using
Paint.setFlags, Paint's
text measurement APIs will report vertical advances instead of horizontal
advances, and Canvas will draw text
vertically.
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 英寸」會顯示為「12.7 公釐」。
如要找到這些設定,請開啟「設定」應用程式,並依序前往「系統」>「語言與地區」。