Android implements floating controls and android floating controls

Source: Internet
Author: User

Android implements floating controls and android floating controls


Implement desktop View, such as desktop lyrics

1) view to be displayed on the desktop, which is mounted to WindowManager through WindowManager. addView;Note, WindowManager object source,The source code is explained. And configure WindowManager. LayoutParams of the view.
1-1) WindowManager. LayoutParams. typeSet to WindowManager. layoutParams. TYPE_SYSTEM_OVERLAY; the desktop UI cannot directly setOnClickListener (). The onTouchEvent () function of the View is also invalid and set to WindowManager. layoutParams. TYPE_SYSTEM_ALERT (2003) or WindowManager. layoutParams. TYPE_PHONE (2002) is valid.
1-2) WindowManager. LayoutParams. flagSet it to LayoutParams. FLAG_NOT_TOUCH_MODAL | LayoutParams. FLAG_NOT_FOCUSABLE
If WindowManager. LayoutParams. type is set to, if flag is not set to the two flags, other components cannot obtain the touch and focus events.
After setting these two attributes, you can get the Touch and Focus events.

2) Declare permissions in androidManifest
<Uses-permission android: name = "android. permission. SYSTEM_ALERT_WINDOW"/>


Private void initDestopText (View childView) {// WindowManager obtained directly through Activity. When the act exits, the Desktop component also exits. // WindowManager wm = (WindowManager) getSystemService (WINDOW_SERVICE); // You must obtain WindowManager through getApplicationContext (). In this case, after the Application is terminated, the floating control will be exited WindowManager wm = (WindowManager) getApplicationContext (). getSystemService (WINDOW_SERVICE); WindowManager. layoutParams params = new WindowManager. layoutParams (); // params. type = WindowManager. layoutParams. TYPE_SYSTEM_OVERLAY; // If set to params. type = WindowManager. layoutParams. TYPE_PHONE; // params. flags = LayoutParams. FLAG_NOT_TOUCH_MODAL | LayoutParams. FLAG_NOT_FOCUSABLE; params. width = WindowManager. layoutParams. WRAP_CONTENT; params. height = WindowManager. layoutParams. WRAP_CONTENT; wm. addView (childView, params );}





How to Implement the Android floating control?

The author said something similar to the letter index scroll bar on the right of many Address Book software? Go to the android bus website to view the answer details>
 
How to dynamically insert controls in android

I wrote the code for you for half an hour and passed my test ~

Run the command to view the result ~ When you perform the key remove operation, you need to write comments to you ~

Layout file content of the layout:
----------------------------------------------------------------------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" android: id = "@ + id/linearlayout">

<LinearLayout android: id = "@ + id/LinearLayout01"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content">
<Button android: layout_height = "wrap_content" android: id = "@ + id/add"
Android: text = "Add" android: layout_width = "100px"> </Button>
<Button android: layout_height = "wrap_content"
Android: layout_width = "100px" android: text = "Remove" android: id = "@ + id/remove"> </Button>
</LinearLayout>
<TextView android: id = "@ + id/TextView01" android: text = "This is textView ."
Android: layout_width = "fill_parent" android: gravity = "center"
Android: layout_height = "50px"> </TextView>

</LinearLayout>
----------------------------------------------------------- ...... The remaining full text>

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.