[英]How to make a Facebook Messenger-like notification like this in Android
I want to implement notifications like the one in the following image. 我想实现下图所示的通知。
Notification appears any time. 通知随时出现。 I think it's of course a background service waiting for new messages from the server then shows this. 我认为这当然是后台服务,等待服务器发出新消息,然后显示此消息。 What I think this is an activity implemented as dialog with this custom UI. 我认为这是使用此自定义UI实施为对话框的活动。 Am I correct? 我对么? And is it a normal startActivity method from the service? 它是服务中的普通startActivity方法吗? And how do I do the transition animation to make it appears slowly from left to right with zooming when show up? 以及如何使过渡动画在显示时通过缩放从左到右缓慢显示?
Check out this link http://www.piwai.info/chatheads-basics . 查看此链接http://www.piwai.info/chatheads-basics 。 He provides information about how to add them on your screen. 他提供有关如何在屏幕上添加它们的信息。
The trick is to add a View
to the WindowManager
like following code 诀窍是像下面的代码一样向WindowManager
添加View
private WindowManager windowManager;
private ImageView chatHead;
public void addView()
{
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.android_head);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 100;
windowManager.addView(chatHead, params);
}
Don't forget to add the permission <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
不要忘记添加权限<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.