如何保持弹出窗口打开在运行时在Android中,当方向改变? [英] How to keep Popup window opened when orientation changes at run time in Android?

查看:124
本文介绍了如何保持弹出窗口打开在运行时在Android中,当方向改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个弹出窗口,其中包含每月视图拿起日期。当我改变方向,由于Android的遍布加载的活动我再次弹出窗口变得消失。我怎样才能使它打开时的方向在运行时的变化?

I have created a Popup window which contains month view to pick up date. When I changes orientation, due to Android loads an activity all over again my popup Window gets disappears. How can I make it opened even when orientation changes at runtime?

推荐答案

包括安卓configChanges =定向 AndroidManifest.xml中到活动显示窗口。这样做会告诉机器人,你会自己处理方向变化,最终它不会破坏你的活动,保持显示的窗口。

include android:configChanges="orientation" in your AndroidManifest.xml to the activity displaying window. Doing this tells android that you are going to handle orientation change yourself and eventually it will not destroy your activity and keeping the window displayed.

如果你没有不同的布局为纵向和横向模式这项技术是不错的。但是,如果你这样做,你还可以通过检测方向模式下面执行自定义布局实现:

This technique is good if you dont have different layouts for portrait and landscape mode. However, if you do, you may still perform custom layout implementation by detecting the orientation mode as below:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        Log.i("orientation", "Orientation changed to: Landscape");
    else
        Log.i("orientation", "Orientation changed to: Portrait");
}

为preVIEW,下载并安装此示例应用

这篇关于如何保持弹出窗口打开在运行时在Android中,当方向改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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