简体   繁体   中英

How do I make an app/service for virtual/soft buttons for (Home, menu, Back, Search) always on top?

I want make an app/service that looks like (Nexus One touch buttons) for the navigation keys (Home, menu, Back, Search)

The buttons should always stay on top and send the command to the actually app that's running.

Someone have ideas and sample codes how to do that?

Update:

I also see and test an app which shows a "cracked display" always on top so that technique maybe should be useful to always show the buttons on top.

Those function, show the button and catch the "touch event" and send the event to the active program should be in a service module which runs in background.

You cannot do this kind of application. First, you cannot keep an app always on top, then you cannot dispatch key events to other apps.

You could do this:

            WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    System.out.println("Accesibilty cargado correctametne");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mTopView = (ViewGroup) inflater.inflate(R.layout.resourceshower, null);
    LayoutParams mWmlp = new WindowManager.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    mWmlp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
    mWmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    mWmlp.width = 100; //size of window
    mWmlp.height = 50;//size of window
    mWmlp.format = PixelFormat.TRANSPARENT;
    mWmlp.x =50; //position of window
    mWmlp.y = 50; //position of window
    mWindowManager.addView(mTopView, mWmlp);

Then if you want to get button clicks inside it, in the layout you are inflating (R.layout.resourceshower) on the buttons add this: android:onClick="launch" and create a public method with the same name like: public void launch(View v){..} you must create this method in the service/activity you create the floating window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM