弹出窗口一样any.do [英] popup window like any.do

查看:275
本文介绍了弹出窗口一样any.do的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个应用程序,显示未接来电,并在弹出窗口中未读短信。它也有一个提醒功能(可关闭弹出窗口,并在指定时间后打开它)。它类似于any.do.的弹出窗口

我能够通过使用WindowManger创建这样的窗口,但由于某些原因而我不理解为止,弹出窗口在一段时间后会消失(尽管它应该被打开,直到用户关闭它,或点击提示按钮,这可能需要几个小时)。

这是我创建的现有弹出窗口

 窗口管理=(窗口管理器)context.getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);
    this.inflater = LayoutInflater.from(上下文);
    PARAMS =新WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.BOTTOM;
    vgPopupWindow =(ViewGroup中)LayoutInflater.from(上下文).inflate(R.layout.popup_mainwindow,NULL);
    vgPopupContent =(ViewFlipper)vgPopupWindow.findViewById(R.id.popup_content);
    vgPopupAreaContent =(ViewGroup中)vgPopupWindow.findViewById(R.id.popup_area_content);
    vgPopupAreaActions =(ViewGroup中)vgPopupWindow.findViewById(R.id.popup_area_actions);
    vgPopupTabs =(的LinearLayout)vgPopupWindow.findViewById(R.id.popup_tabs);
    vgPopupHeader =(的LinearLayout)vgPopupWindow.findViewById(R.id.popup_main_header);
    windowManager.addView(vgPopupWindow,则params);
 

,因为我不知道,如果窗口管理器是真正正确的道路,我也试着用以下的样式做同样的活动。

 <样式名称=PopupWindow父=CustomTheme>
    <项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
    <项目名称=机器人:windowNoTitle>真< /项目>
    <项目名称=机器人:windowFullscreen>假< /项目>
    <项目名称=机器人:windowIsTranslucent>真< /项目>
 

它现在看起来就像窗口管理器的版本,但有一个问题:我不能访问它下面我的应用程序的窗口,因为窗口的半透明部分看起来很完美,但阻止任何click事件到下面的窗口,因此我不能滚动,或用它做任何事情。像any.do我只是想该窗口显示出来,但不能阻止工作而popupwindow打开下面的窗口中的可能性。

编辑:我希望看到的弹出窗口的底部,覆盖了窗口的30%,但能滚动窗口在它之下(也对其执行click事件)在同一时间。

所以我的问题是:

  1. 是窗口管理器的正确方式来创建此popupwindow?
  2. 如果是,为什么它消失了,有时没人要?我怎么能prevent呢?
  3. 如果没有,我怎么能创建一个行为像我的窗口管理器窗口创建活动?
  4. 或者是两种方式错了吗?在这种情况下;最新的正确方法?
解决方案

下面是code我以前做的同样的事情

 公共类PopupActivity延伸活动{

    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        AlertDialog.Builder ADB =新生成器(本);
        AlertDialog dialogTest = adb.setTitle(测试题)
                .setMessage(测试信息)
                .setNeutralButton(按钮,新OnClickListener(){

                    @覆盖
                    公共无效的onClick(DialogInterface对话,诠释它){
                        // 做一点事
                        PopupActivity.this.finish();
                    }
                })。创建();
        adb.setCancelable(假);
        dialogTest.show();
    }
}
 

和XML风格(最初张贴在这里 http://stackoverflow.com/a/2700683/995020

 <样式名称=Theme.Transparent父=AppTheme>
    <项目名称=机器人:windowIsTranslucent>真< /项目>
    <项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
    <项目名称=机器人:windowContentOverlay> @空< /项目>
    <项目名称=机器人:windowNoTitle>真< /项目>
    <项目名称=机器人:windowIsFloating>真< /项目>
    <项目名称=机器人:backgroundDimEnabled>假< /项目>
< /风格>
 

设置样式在清单文件的活动。然后就是启动活动中,你要显示的弹出窗口的任何时间。你可以添加额外的数据到一个意向,并用它来定制弹出。

i am writing an app that shows missed calls and unread sms in a pop up window. it also has a reminder feature (to close the pop up window and open it after a specified time). its similar to the popup window of any.do.

i was able to created such a window by using the WindowManger, but for some reasons which i dont understand so far, the pop up window disappears after some time (although it should be opened untill the user closes it, or clicks on the reminder button which could take hours).

this is how i created the existing popup window

windowManager = (WindowManager) context.getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);              
    this.inflater = LayoutInflater.from(context);
    params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.BOTTOM;
    vgPopupWindow = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.popup_mainwindow, null);
    vgPopupContent = (ViewFlipper) vgPopupWindow.findViewById(R.id.popup_content);
    vgPopupAreaContent = (ViewGroup) vgPopupWindow.findViewById(R.id.popup_area_content);
    vgPopupAreaActions = (ViewGroup) vgPopupWindow.findViewById(R.id.popup_area_actions);
    vgPopupTabs = (LinearLayout) vgPopupWindow.findViewById(R.id.popup_tabs);
    vgPopupHeader = (LinearLayout) vgPopupWindow.findViewById(R.id.popup_main_header);
    windowManager.addView(vgPopupWindow, params);

because i was not sure if the WindowManager is really the right way for that, i also tried to do the same with an activity with following style

<style name="PopupWindow" parent="CustomTheme">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowIsTranslucent">true</item>

its looks now just like the WindowManager version, but has one problem: i can not access the window of my app below it, because the translucent parts of the window look perfect, but block any click events to the window below, so that i can not scroll it or do anything with it. like in any.do i just want that window to show up, but not to block any possibility to work on the window below while the popupwindow is opened.

EDIT: i want to see the pop up window at the bottom, covering 30% of the window, but be able to scroll the window under it (and also perform click events on it) at the same time.

so my questions are:

  1. is the WindowManager the right way to create this popupwindow?
  2. if yes, why does it disappear sometimes unwanted? how can i prevent it?
  3. if no, how can i create an activity that behaves like the window i created with the WindowManager?
  4. or are both ways wrong? in this case; whats the right way?

解决方案

Here is the code I used to do the same thing

public class PopupActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AlertDialog.Builder adb = new Builder(this);
        AlertDialog dialogTest = adb.setTitle("Test title")
                .setMessage("Test message")
                .setNeutralButton("Button", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // do something
                        PopupActivity.this.finish();
                    }
                }).create();
        adb.setCancelable(false);
        dialogTest.show();
    }
}

and the XML style(originally posted here http://stackoverflow.com/a/2700683/995020)

<style name="Theme.Transparent" parent="AppTheme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

Set the style for the activity in the manifest file. And then just start the activity any time you want to show the popup window. You may add EXTRA data to an intent and use it for customizing the popup.

这篇关于弹出窗口一样any.do的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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