Created
April 4, 2016 09:36
-
-
Save rflechner/cd554482152a943540e939f0eb1831d4 to your computer and use it in GitHub Desktop.
Android button like FB chat bubble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace UILearning | |
open System | |
open Android.App | |
open Android.Content | |
open Android.OS | |
open Android.Runtime | |
open Android.Views | |
open Android.Widget | |
open Android.Graphics | |
[<Service>] | |
type UIService() = | |
inherit Service() | |
let mutable count:int = 1 | |
override __.OnBind(intent:Intent) = | |
base.OnBind intent | |
// member OnCreate : unit -> unit | |
// member OnDestroy : unit -> unit | |
override __.OnStart(intent:Intent,startId:int) = | |
let param=new WindowManagerLayoutParams() | |
param.Flags <- WindowManagerFlags.NotFocusable | |
let view = new Button(__) | |
view.LayoutParameters <- new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent) | |
view.SetBackgroundColor(Color.Red) | |
view.Text <- "Notif !" | |
let parent = view.Parent :?> ViewGroup | |
if parent <> null | |
then | |
parent.RemoveView view | |
param.Format <- Format.Rgba8888 | |
param.Type <- WindowManagerTypes.SystemAlert | |
param.Gravity <- GravityFlags.Bottom ||| GravityFlags.Right | |
param.Width <- | |
if parent <> null | |
then WindowManagerLayoutParams.WrapContent | |
else view.LayoutParameters.Width | |
param.Height <- | |
if parent <> null | |
then WindowManagerLayoutParams.WrapContent | |
else view.LayoutParameters.Height | |
let windowManager = | |
__.ApplicationContext.GetSystemService(Context.WindowService).JavaCast<IWindowManager>() | |
windowManager.AddView(view, param) | |
view.Click.Add(fun _ -> | |
view.Text <- sprintf "%d clicks!" count | |
count <- count + 1 | |
) | |
() | |
// http://stackoverflow.com/questions/4481226/creating-a-system-overlay-window-always-on-top | |
[<Activity (Label = "UILearning", MainLauncher = true)>] | |
type MainActivity () = | |
inherit Activity () | |
let mutable count:int = 1 | |
override __.OnCreate (bundle) = | |
base.OnCreate (bundle) | |
__.SetContentView (Resource_Layout.Main) | |
let button = __.FindViewById<Button>(Resource_Id.MyButton) | |
button.Click.Add (fun _ -> | |
button.Text <- sprintf "%d clicks!" count | |
count <- count + 1 | |
let t = typeof<UIService> | |
let intent = new Intent(__, t) | |
__.StartService intent |> ignore | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment