[英]How to implement toast overlay in Google TV
我正在為Google TV創建一個應用程序。 我正在嘗試在廣播的頂部創建自定義吐司覆蓋。
我創建了自定義吐司,如下所示:
<?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應用程序的視圖中實現它:
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();
我的問題是我如何使該應用程序在應用程序中顯示正常的廣播信息,以便在觀看過程中觸發此覆蓋圖?
任何幫助,不勝感激。
以下是一些方法:
您可以創建一個應用程序,用戶每次要在直播中看到這種吐司之前必須明確啟動。 該應用程序將進行透明的活動,然后顯示吐司或僅顯示帶有信息的視圖。 您的活動將阻止所有其他與廣播的互動,例如更改頻道。
從服務中調用吐司或透明活動。 看看這個開源的應用程序: https : //github.com/entertailion/Overlay-for-GTV
除了使用Toast或透明視圖,您還可以使用Android支持的系統警報窗口,將視圖覆蓋在其他任何活動之上。 您的清單中需要“ android.permission.SYSTEM_ALERT_WINDOW”,並且需要將窗口類型設置為“ WindowManager.LayoutParams.TYPE_SYSTEM_ALERT”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.