代码之家  ›  专栏  ›  技术社区  ›  Hong

如何让应用程序在Android TV上使用不同的横幅?

  •  0
  • Hong  · 技术社区  · 4 年前

    应用程序使用横幅如下:

    <application
        ...
        android:banner="@mipmap/ic_launcher" >
        ...
    </application>
    

    Android Studio的Asset Studio用于创建横幅: enter image description here

    它完全按照预期工作。

    由于Android TV应用程序对横幅有不同的要求,是否有一种方法可以在不影响其他设备的情况下仅为Android TV指定横幅?

    [编辑]

    我很欣赏建议使用不同活动的答案。目前的发射活动非常适合电视。我想用同样的活动。我一直在寻找一种方法,让应用程序在Android电视上自动使用一组不同的资源。如果不可能,我将通过创建一个自动切换到原始启动活动的虚拟活动来回答这个问题。

    0 回复  |  直到 4 年前
        1
  •  3
  •   Ian G. Clifton    4 年前

    移动设备使用图标,电视设备使用横幅,因此您可以将它们指向单独的资源:

    <application
        android:icon="@mipmap/ic_launcher"
        android:banner="@mipmap/ic_app_banner"
        ...
    
        2
  •  2
  •   vishal N    4 年前

    Step1:为Android TV创建单独的活动

    步骤2:使用 标签

    <activity
     ...
    android:banner="@mipmap/ic_launcher">
    </activity>
    
        3
  •  1
  •   Lalit Fauzdar    4 年前

    作为 official documentation 我引述如下:

    使用android:banner属性 <application> 标签供应 所有应用程序活动的默认横幅,或使用 <activity> 标签为特定活动提供横幅。

    您可以使用 <活动> 标签使用不同的横幅。

        4
  •  0
  •   Hong    3 年前

    所有的答案都给了我一些提示。这是我的最终解决方案,已被Google Play接受。 在AndroidManifest.xml中,为应用程序标记指定手机和平板电脑的图标。(安卓系统:图标=“@mipmap/ic_launcher”)。必须这样做。否则, the app would crash .

    <application
        android:name="androidx.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher_round"
        android:largeHeap="true"
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true"
        tools:replace="android:theme, android:label">
    

    这里是关键:android:icon=“@mipmap/ic_launcher_round”适用于手机和平板电脑,android:banner=“@mipmap/ic_banner”适用于android TV,位于启动器活动的活动标签中:

    <activity
        android:name=".OnviferActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:icon="@mipmap/ic_launcher_round"
        android:banner="@mipmap/ic_banner"
        android:label="@string/app_name"
        android:screenOrientation="@integer/screen_orientation">
    

    手机和平板电脑将使用ic_launcher_round,安卓电视将自动使用ic_banner。