简体   繁体   English

如何在Google TV中实现吐司覆盖

[英]How to implement toast overlay in Google TV

Im creating an application for Google TV. 我正在为Google TV创建一个应用程序。 I am trying to create a custom toast overlay over the top of the broadcast. 我正在尝试在广播的顶部创建自定义吐司覆盖。

I have created the custom toast as follows: 我创建了自定义吐司,如下所示:

<?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>

and implemented it in the view of the googleTV app: 并在googleTV应用程序的视图中实现它:

     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();

My question is how do i make this app show the normal broadcast information in the app so that I can trigger this overlay during viewing? 我的问题是我如何使该应用程序在应用程序中显示正常的广播信息,以便在观看过程中触发此覆盖图?

Any help greatly appreciated. 任何帮助,不胜感激。

Here are some ways of doing this: 以下是一些方法:

  1. You can create an app the user has to explicitly launch every time before they want to see this kind of toast on their live broadcast. 您可以创建一个应用程序,用户每次要在直播中看到这种吐司之前必须明确启动。 The app will have a transparent activity and then display the toast or just a view with the information. 该应用程序将进行透明的活动,然后显示吐司或仅显示带有信息的视图。 Your activity will block all other interactions with the broadcast like changing channels. 您的活动将阻止所有其他与广播的互动,例如更改频道。

  2. Invoke the toast or transparent activity from a service. 从服务中调用吐司或透明活动。 Look at this open sourced app: https://github.com/entertailion/Overlay-for-GTV 看看这个开源的应用程序: https : //github.com/entertailion/Overlay-for-GTV

  3. Instead of the toast or transparent view, you can also use a system alert window which is supported by Android to overlay a view on top of any other activity. 除了使用Toast或透明视图,您还可以使用Android支持的系统警报窗口,将视图覆盖在其他任何活动之上。 You need "android.permission.SYSTEM_ALERT_WINDOW" in your manifest and you need to set the window type to "WindowManager.LayoutParams.TYPE_SYSTEM_ALERT". 您的清单中需要“ android.permission.SYSTEM_ALERT_WINDOW”,并且需要将窗口类型设置为“ WindowManager.LayoutParams.TYPE_SYSTEM_ALERT”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM