React Native - Android TV - DPad 功能

Pri*_*kar 6 android reactjs react-native google-play-console

我已经向 Android 电视的 Google Play 商店发布了一个 React Native 应用程序。

对于电视,我收到了以下通知:

缺少 DPad 功能 您的应用程序需要用户交互来进行菜单或应用程序导航。请使用 DPad 确保所有菜单和应用程序导航功能齐全。请参阅我们的 DPAD 控制和硬件声明文档。

我们如何为 React-Native Android 应用程序启用方向键导航?

如果您需要更多信息,请告诉我。

Pri*_*kar 5

最后,我解决了反应本机 Android 电视应用程序的方向键导航和横幅的问题。

问题是:(这包括甚至不属于问题的问题)

1.没有全尺寸的应用横幅

修复: create a folder called drawable在 下"your-app/android/app/src/main/res",添加一个 png 文件( dimensions 320px x 180px and 320 dpi),最重要的部分是,within image, there should be no other text then application name您已经发布了 APK。

2. 不支持的硬件用途

修复:我在发布问题之前修复了此问题,但如果您遇到此问题,

refer the answer by **@reidisaki** on this question.
Run Code Online (Sandbox Code Playgroud)

3.缺少DPad功能(问题中提出的实际问题)

修复:我在屏幕上使用 InputText。好吧,react-native version 0.56在 android/android 电视下面,InputText cannot be focused by d-pad(方向键)。I stopped using TextInput它修复了方向键导航。它也可以在 Android 模拟器中使用,以测试该应用程序。

为了使我的应用程序更符合电视标准,在AndroidManifest.xml中,我将活动启动器升级为:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

要将 Android 电视主题升级为 Leanback:

  1. added leanback library到依赖项部分下的“app-name/android/app/build.gradle”:

    dependencies {
    ....
    compile "com.android.support:leanback-v17:${rootProject.ext.supportLibVersion}"
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. AndroidManifest.xml中,我将主题更改为@style/Theme.Leanback

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:banner="@drawable/banner"
      android:allowBackup="true"
      android:theme="@style/Theme.Leanback">
      ....
    </application>
    
    Run Code Online (Sandbox Code Playgroud)