8

Currently I am trying to make an activity that can be moved on the screen , in other words this activity can float on the screen. I know I am missing something that should be added to achieve this functionality.

What should I do to achieve floating activity which can be moved around anywhere on the screen?

Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
  • Float above other apps or just float above the background? – Delyan Aug 20 '13 at 17:25
  • free float above background. – Umer Farooq Aug 20 '13 at 17:31
  • I think for something like this you are better off using a `Fragment`. I say this is because the only logical reason you would want that is to be able to see other things behind it. Creating a standalone fragment that floats is much better design than using an `Activity`. Just some advice. – Andy Aug 20 '13 at 17:41
  • fine but fragment is an extension of activity. By default it also takes up the whole screen and can't float around. Well if fragment works better in such cases, I will use fragments but I want to know how can I make a free floating app – Umer Farooq Aug 20 '13 at 17:44
  • SYSTEM_OVERLAY allows you to float above other apps. You want `android:windowIsTranslucent` in the theme of your activity (so that you Activity window is transparent, you don't need to make a new one). Then you have a choice - either keep the activity full screen and move Views in it (easy) or resize and move the actual window (hard). (Fragments are irrelevant to the discussion in my humble opinion) – Delyan Aug 20 '13 at 17:45
  • the easy part has already been done :). The question is about free floating activity i-e; Moving around a window – Umer Farooq Aug 20 '13 at 17:55

2 Answers2

4

If you're looking to do something similar to the Facebook chat circles (where you have a view on top of other apps) then take a look here: http://www.cloudinfy.com/2013/06/android-chat-head-view-like-in-facebook.html

Basically you need to start a service and add a view to the window manager.


If you're looking to simply create an activity to look like a dialog then have a look here: Android Activity as a dialog

This is very similar to a normal activity but the theme is set to Theme.Dialog

Community
  • 1
  • 1
Randy
  • 4,351
  • 2
  • 25
  • 46
0

There's a good solution here: http://cases.azoft.com/android-tutorial-floating-activity/ They just add an attribute to the theme of a tablet Activity:

<item name="android:windowIsTranslucent">true</item>

If any problems on KitKat devices, add some lines to the theme:

<item name="android:windowIsFloating">true</item>  
<item name="android:windowCloseOnTouchOutside">false</item>  
<item name="android:colorBackgroundCacheHint">@null</item>  
<item name="android:backgroundDimEnabled">true</item>
ice.cube
  • 505
  • 4
  • 7