显示活动作为片覆盖窗口 [英] Display Activity as overlay window on tablets

查看:83
本文介绍了显示活动作为片覆盖窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么了present的活动作为片重叠的窗口?这方面的一个例子是新的Google+应用是在这里看到:

How do you present an Activity as an overlay window on tablets? An example of this is the new Google+ app as seen here:

重要的是我要的动作条是窗口的一部分,并为活动的下方变暗看到的截图。

Importantly I want the ActionBar to be part of the window and for the Activity beneath to be dimmed as seen in the screenshot.

感谢

推荐答案

您可以只使用对话的主题。要做到这一点,只是写在清单:

You can just use dialog theme. To do this, just write in Manifest:

 android:theme="@android:style/Theme.Dialog"

android:theme="@android:style/Theme.Holo.Dialog"

或只是通过创建自己的主题,在styles.xml:

or just by creating your own theme in styles.xml:

<style name="MyDialogTheme" parent="Theme.Holo.Dialog">
...
</style>

您可以通过在价值观XLARGE或值,大的文件夹创建styles.xml设置这样的主题XLARGE或大屏幕。

You can set such theme for xlarge or large screen by creating styles.xml in values-xlarge or values-large folders.

如果您希望只设置这个主题的平板电脑,那么你就可以动态地通过检查屏幕大小像这样更改主题:

If you want to set this theme only for tablets, then you can change theme dynamically by checking the screen size like this:

if (Configuration.SCREENLAYOUT_SIZE_XLARGE)
{
//setTheme(yourDialogTheme);
}

如果你想用行动吧对话框,请检查这个答案。您可以通过创建自定义对话框做到这一点。

Please check this answer if you want dialog with action bar. You can do this by creating your custom dialog.

对话为主题的活动与操作栏

自定义对话框

编辑: 从谷歌组帖子一个答案。尝试这个 在你的XML与样式:

An answer from google group post. Try this in your xml with styles:

<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
        <item name="android:windowActionModeOverlay">true</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

在Java的code

In Java code

public static void showAsPopup(Activity activity) {
        //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
        activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        LayoutParams params = activity.getWindow().getAttributes(); 
        params.height = LayoutParams.FILL_PARENT;
        params.width = 850; //fixed width
        params.alpha = 1.0f;
        params.dimAmount = 0.5f;
        activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 
    }

这篇关于显示活动作为片覆盖窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆