4

In my application, I need to draw a bitmap on top of all the apps running. I created a view which is invisible and overlays on top of all the apps. with this overlay view I can draw bitmaps at the given position , But I am unable to draw the bitmap on top of the Navigation Bar.I used the following layout parameters.

    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_FULLSCREEN
    |WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    |WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
    |WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR 
    |WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,

I need help in solving this issue. Thanks in advance

M D
  • 47,665
  • 9
  • 93
  • 114
sash
  • 1,124
  • 2
  • 15
  • 32

1 Answers1

5

I have solved the issue myself , to draw on top of navigation bar at the bottom of the android , I have to give an offset in the Y position while defining the windowManager.Layout params as below.

w = new android.view.WindowManager.LayoutParams(-1, -1,0,-navigationBarHeight(),    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_FULLSCREEN
    |WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    |WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
    |WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR 
    |WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, Pixel.Translucent);
    f.addView(v, w);

note: This only works when the navigation bar is translucent

Lamorak
  • 10,957
  • 9
  • 43
  • 57
sash
  • 1,124
  • 2
  • 15
  • 32
  • Hi, @sash! I want to ask you about where I should place this code and what type of f? – Kirill Volkov Apr 21 '14 at 12:15
  • Does this work for you all the time? It seems that it only works when the Navigation bar is semi transparent (on launcher and some of google apps) but if it's completely opaque, it still draw behind it – Vlad Mar 29 '15 at 19:51
  • @Vlad, it does not work for me always either (it works most of the time -- I found only a couple of apps (k-9 among them) It probably has something to do with min supported version) . It is not an opaque vs. translucent differentiation though. Not sure what it is... – miha Sep 03 '15 at 13:07
  • @miha You are right.. it only works when the background of the navigation bar is transparent – Vlad Sep 03 '15 at 13:11
  • @Vlad, I was just playing around - in one custom application, it made a difference when I used target SDK. If target SDK was set to 21 or above, you could draw over navbar, otherwise not. On another app (this made no difference). Flaky... – miha Sep 03 '15 at 14:09
  • 1
    seems from 5.0 on this is not possible anymore: http://room-15.github.io/blog/2015/03/17/overlaying-the-system-navigation-bar/ – Boy Mar 16 '16 at 14:08
  • @Vlad Did you ever find a way to get it working in all apps? I can't get mine to draw over the navbar in certain apps like Chrome and Tinder profile view mode only! It simply draws under the navbar. – Flyview Oct 19 '16 at 18:26
  • @Flyview Nope. Sometimes the navbar is transparent so it seems you're drawing above it, but you don't actually ever draw above the navbar. This is by design – Vlad Oct 25 '16 at 06:59