TV 应用中有一个比较常见的词Leanback
,找了半天翻译,靠谱点儿的就是“靠着看” - -
Declare a TV Activity
不同于手机 APP 应用,TV 应用的 Launcher 声明使用的是 CATEGORY_LEANBACK_LAUNCHER
<application
android:banner="@drawable/banner" >
...
<activity
android:name="com.example.android.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.android.TvActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Leanback">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
</application>
如果不使用 CATEGORY_LEANBACK_LAUNCHER 声明,应用将不会出现的 Google Play,使用开发工具加载 APP 到 TV 也不会出现在界面上
Declare Leanback support
<manifest>
<uses-feature android:name="android.software.leanback"
android:required="false" /> // true 只运行在 Leanback UI, false 可以运行在手机、手表、TV等设备
...
</manifest>
Declare touchscreen not required
声明不依赖触摸屏,这是必须的,否则不会出现的TV 上的 Google Play 中
<manifest>
<uses-feature android:name="android.hardware.touchscreen"
android:required="false" />
...
</manifest>
Provide a home screen banner
<application
...
android:banner="@drawable/banner" >
...
</application>
Use the android:banner attribute with the tag to supply a default banner for all application activities, or with the tag to supply a banner for a specific activity.
banner 的要求
Banners are images that represent the face of your app or game on the home screens of Android TV devices and serve as a way for users to launch your app. Here are the requirements for your banner image:
Size: 320 x 180 px, xhdpi resource
文字必须包含在图片中,如果应用是多语言的,还有提供对应的banner。
Change the launcher color
当启动 TV 应用时,系统会使用动画如展开的实心圆,为了自定义动画颜色,可以使用 android:colorPrimary
属性,同时设置两个额外的 transition overlap 属性为 true
<resources>
<style ... >
<item name="android:colorPrimary">@color/primary</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
</style>
</resources>
Add TV support libraries
TV 支持包不是必须的,但是推荐使用 v17 leanback library,依赖于V7、V4等其它包。
开发应用,运行
在 TV 和模拟器上运行 APP 的方法和步骤,和在手机端是一样的。
TV 上开启开发者模式,开启 USB 调试,运行即可。
模拟器直接运行。