可以将它添加到窗口管理后,不点击的EditText [英] Cannot click on EditText after adding it to WindowManager

查看:192
本文介绍了可以将它添加到窗口管理后,不点击的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常动态创建一个布局pretty的。什么我做的是,创造一个EditText,将其添加到RelativeLayout的对象,并把它通过窗口管理器,用户界面​​。我如何获得的EditText要能我做到这一点后,键入?这里是我的code一个JIST

I am creating a layout pretty much dynamically. What I am doing is, creating an EditText, adding it to a RelativeLayout object and putting it to UI through WindowManager. How do I get the edittext to be able to type after I do this? Here is a jist of my code

 RelativeLayout layout = new RelativeLayout(this);
 private EditText response = new EditText(this); 
 **Set width/height/extra**
 layout.addView(response, params);  //Params are set properly
 WindowManager myWindow = (WindowManager) getSystemService(WINDOW_SERVICE);
 myWindow.addView(layout, params_window);

编辑:我想实现像在应用程序的LilyPad弹出消息(我不知道,如果你知道它)。我试图动态地更改文本。这是我做的:

I am trying to achieve a popup message like in the app LilyPad (I am not sure if you know about it). I am trying to change the text dynamically. Here is what I did:

  LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  myView = layoutInflater.inflate(R.layout.popups, null );
  message = (TextView)myView.findViewById(R.id.message);
  message.setText(text);

那之后,我下面@android开发者的方法。但我得到一个空指针异常的message.setText(文字)的一部分。消息是一个初始化为一个TextView对象,我检查没有在popups.xml文件一个TextView id'd消息。 这将固定我并没有主动的窗口管理器。对不起忽略此,请请参阅我的问题,编辑III

Then after that, I am following @android developer's method. But I am getting a null pointer exception in the message.setText(text) part. Message is a initialized as a TextView object and I checked there is a TextView id'd message in the popups.xml file. THIS IS FIXED I did not initiate the windowManager. Sorry ignore this please Please see my issue in Edit III

修改二:下面是我想要的另一张照片。 http://imgur.com/yXJ36n1 灰色框是RelativeLayout的XML文件。例如果我在我的Facebook墙上我想Facebook的墙出现在黑色区域的顶部,并希望它能够滚动在facebook的墙上没有我的应用程序(在的LilyPad等)的干扰。如果我做

EDIT II: Here is another picture of what I want. http://imgur.com/yXJ36n1 The gray boxes are in RelativeLayout in an XML file. Ex. if I am on my facebook wall I want the facebook wall to appear on the black area on top and want it to be able scrollable in the facebook wall without my app interfering (like in LilyPad). If I do

      LayoutInflater layoutInflater =    
      (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  myView = layoutInflater.inflate(R.layout.popups, null );

然后配置窗口管理与透明,我们的标志,并加入我的看法,在背景画面不是功能。背景不会暂停,但我不能像滚动homescreens为例。这个问题似乎是该RelativeLayout的占据了整个屏幕。这是在XML文件中定义我的RelativeLayout的性质

then configure WindowManager with the Transparent w.e flags, and add my view, the background screen is not functional. Background doesn't pause but I cannot like scroll through homescreens for example. The problem seems to be that the RelativeLayout takes up the entire screen. This is my RelativeLayout properties defined in the xml file

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" 

修改四: <一个href="https://lh4.ggpht.com/gnNfCsUU7cTCTedhny-wej-nbGmL1fktcw5qo92CCOLQ9ySG5t4pCRKYSt7u--kjpw=h900-rw" rel="nofollow">https://lh4.ggpht.com/gnNfCsUU7cTCTedhny-wej-nbGmL1fktcw5qo92CCOLQ9ySG5t4pCRKYSt7u--kjpw=h900-rw这里是一个pictureo˚F的LilyPad

EDIT IV: https://lh4.ggpht.com/gnNfCsUU7cTCTedhny-wej-nbGmL1fktcw5qo92CCOLQ9ySG5t4pCRKYSt7u--kjpw=h900-rw Here is a pictureo f LilyPad

推荐答案

这里是你如何把一个观点放在第一位:

here's how you put a view on top of everything:

final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=...
final ViewGroup parent=(ViewGroup)view.getParent();
if(parent!=null)
  parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=view.getLayoutParams().width;
param.height=view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
// TODO handle overlapping title bar and/or action bar
// TODO you must add logic to remove the view
// TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW

您可以把内部的XML的观点,如果你想很容易地看到它应该是什么样子。在code我写将从您的布局分离,并将其放在窗口本身。

you can put the view inside XML if you wish to easily see how it should look like. the code i've written will detach it from your layout and put it on the window itself.

这篇关于可以将它添加到窗口管理后,不点击的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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