android - 如何在 Google TV 中实现 toast 覆盖

标签 android overlay toast google-tv

我正在为 Google TV 创建一个应用程序。我正在尝试在广播顶部创建自定义 toast 叠加层。

我已经创建了自定义 toast,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_layout_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
android:orientation="horizontal"
android:padding="5dp" >

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:textColor="#000" />

</LinearLayout>

并在 googleTV 应用的 View 中实现它:

     LayoutInflater inflater = getLayoutInflater();

            View layout = inflater.inflate(R.layout.main,
            (ViewGroup) findViewById(R.id.custom_toast_layout_id));

            // Toast...
            Toast toast = new Toast(getApplicationContext());
            toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.setView(layout);
            toast.show();

我的问题是如何让这个应用程序在应用程序中显示正常的广播信息,以便我可以在观看期间触发这个覆盖?

非常感谢任何帮助。

最佳答案

这里有一些方法:

  1. 您可以创建一个应用程序,用户必须在每次想要在直播中看到这种 toast 之前明确启动。该应用程序将有一个透明的 Activity ,然后显示 toast 或只是一个包含信息的 View 。您的 Activity 将阻止与广播的所有其他交互,例如更改 channel 。

  2. 从服务调用 toast 或透明 Activity 。看看这个开源应用程序:https://github.com/entertailion/Overlay-for-GTV

  3. 除了 toast 或透明 View 之外,您还可以使用 Android 支持的系统警报窗口将 View 覆盖在任何其他 Activity 之上。您的 list 中需要“android.permission.SYSTEM_ALERT_WINDOW”,并且需要将窗口类型设置为“WindowManager.LayoutParams.TYPE_SYSTEM_ALERT”。

关于android - 如何在 Google TV 中实现 toast 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15586960/

相关文章:

android - android/dev/input/eventX 文件的用途是什么?

android - MapView添加Overlay后没有滚动

android - 如何设置Kotlin中的Toast的重力(属性样式)(出现错误)?

java - 无法在 Samsung A5 (2016) 上使用 Toast

Android Studio 无法解析符号 'android'

android - 在单击已经具有背景 XML 的相对布局时应用波纹效果

java - 在图像上添加按钮

layout - flutter |如何在任何叠加层之上显示 AlertDialog?

Android:无法显示 toast

android - 为什么 Google Nexus 7 实际上是 7.3"in Eclipse, whereas it is 7"?