Android Implements desktop display content

Source: Internet
Author: User

Get WindowManager Object

WindowManager wm = (WindowManager) getapplicationcontext (). Getsystemservice (Window_service);

Initialize the view that the desktop needs to display
View view = Layoutinflater.from (context). Inflate (r.layout.message_item_im_left, NULL);

Get Layoutparams Object Settings view on the desktop display style
Windowmanager.layoutparams params = new Windowmanager.layoutparams ();


Params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
Params.flags = Layoutparams.flag_not_touch_modal | layoutparams.flag_not_focusable;
Set the width height of the view
Params.width = WindowManager.LayoutParams.FILL_PARENT;
Params.height = WindowManager.LayoutParams.WRAP_CONTENT;

Set transparency
Params.alpha = 80;

Params.gravity=gravity.left| Gravity.top;
Set X, y initial values as the origin in the upper-left corner of the screen
params.x = 0;
Params.y = 0;

Add a view to the desktop display
Wm.addview (view, params);

Permissions required to open

<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name= "Android.permission.INTERNAL_SYSTEM_WINDOW"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.