I am implementing windowManager in my Service Class
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
I added a view in my windows manager but the click listener of that view is not working .
mView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(),"onClick", Toast.LENGTH_LONG).show();
}
});
Here are the layout params .
WindowManager.LayoutParams params = new WindowManager.LayoutParams(130,130);
params.type=WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
params.flags=WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
params.format=PixelFormat.TRANSPARENT;
I want that click listener to work properly but its not working so please help me in this regard.
Hi After a long research i found this code. this should work. have a try . Add this line in on-create of your service class. The below contents are the parameters we should pass FLAG_WATCH_OUTSIDE_TOUCH and all. Hope this helps you.
WindowManager.LayoutParams params = new WindowManager.LayoutParams(100, 100, 2007, 8, -3);
Button bb=new Button(this);
bb.setText("Button");
bb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Clicked----><<<<<<<");
}
});
bb.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
System.out.println("Touched =----- > ");
return false;
}
});
params.gravity = Gravity.RIGHT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(bb, params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With