Android TV 官方教程简读1-Building Apps for TV

官方文档

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 调试,运行即可。

模拟器直接运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值