最近要做一個(gè)Wear OS端的App,第一次開發(fā)手表端App,對(duì)開發(fā)的流程做一個(gè)記錄,以備不時(shí)之需。
1.項(xiàng)目框架
<uses-feature android:name="android.hardware.type.watch" />
AndroidManifest最大的區(qū)別是,uses-feature限定了watch這個(gè)類型。
build.gradle腳本基本和Android App項(xiàng)目沒有區(qū)別,只是增加了wear相關(guān)的library依賴。
2.布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_grey"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".SplashActivity"
tools:deviceIds="wear">
</androidx.wear.widget.BoxInsetLayout>
布局的根結(jié)點(diǎn)是BoxInsetLayout,這是專門兼容了手表屏幕的一個(gè)Layout,需要注意的是 app:boxedEdges="all"屬性,可以保證View在手表上展示完全。