Lets start with the simple one. FLAG_DIM_BEHIND is a constant. Its value is 2.
Try this code, it will only work on Android 4+:
B4X:
Dim jo As JavaObject = Activity
Dim Window As JavaObject = jo.RunMethodJO("getContext", Null).RunMethod("getWindow", Null)
Window.RunMethod("addFlags", Array As Object(2))
Dim dimAmount As Float = 0.8
Window.RunMethod("setDimAmount", Array As Object(dimAmount))