【问题标题】:Custom Toast for Google TV谷歌电视的自定义吐司
【发布时间】:2013-03-25 22:47:57
【问题描述】:

我正在为 Google TV 创建叠加层。我创建了一个透明主题,以便通过应用程序可以看到广播,如下所示:

样式.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="Invisible" parent="@android:style/Theme">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

不使用此主题时,我可以使用以下图片显示自定义吐司:

             View layout = inflater.inflate(R.layout.toast,
                        (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();

但是,当我使用此主题时,它不会显示,只会显示标准 toast:

        Toast.makeText(this, "This game is over. Start a new game.", Toast.LENGTH_SHORT).show();

toast 只是在屏幕中间显示一张图片,所以不需要很复杂。

非常感谢任何帮助。

【问题讨论】:

    标签: android themes overlay toast google-tv


    【解决方案1】:

    改为使用该布局创建一个活动。启动 Activity 而不是调用 toast。

    【讨论】:

      【解决方案2】:

      Toast 将包含当前活动活动使用的主题。因此,正如 Leon 所说,如果您创建一个带有您想要的主题的活动,则 toast 将继承该主题。见:Toast background changing to match Activity's Theme

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-04
        • 1970-01-01
        • 2023-02-15
        • 1970-01-01
        • 1970-01-01
        • 2014-04-15
        • 1970-01-01
        相关资源
        最近更新 更多