Android Question Inline java code problem

Jerryk

Active Member
Licensed User
Longtime User
I found java code here for getting the height of ToolBar and StatusBar. I should note that I am not a Java expert.
Java:
#If JAVA
import android.view.Window;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;

public int StatusBarHeight(){
        int result = 0;
        int resId = BA.applicationContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resId > 0) {
            result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
        }
        return result;
    }

public int TitleBarHeight(BA ba) {
        int viewTop = ba.activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
        return (viewTop - StatusBarHeight());
    }
#End If
The function for geting the StatusBar height works.
B4X:
    Private nativeMe As JavaObject
...
    nativeMe = Me


Sub StatusBarHeight As Int
    Dim id As Int = nativeMe.RunMethod("StatusBarHeight", Null)
    Return id
End Sub
In the function for geting the height of the TitleBar, I don't know what to put in the RunMethod function parameter, which is represented in the Java function by "BA ba"
B4X:
Sub TitleBarHeight As Int
    Dim id As Int = nativeMe.RunMethod("TitleBarHeight", ???)     -  witch parameter
    Return id
End Sub
 
Last edited:
Solution
I think I found a solution (I'll test it)
B4X:
Sub TitleBarHeight As Int
    Dim id As Int = nativeMe.RunMethod("TitleBarHeight", Array(GetBA))
    Return id
End Sub

Sub GetBA As Object
    Return nativeMe.RunMethod("getBA", Null)
End Sub

Sagenut

Expert
Licensed User
Longtime User
Not sure but.... The status bar and the soft touch commands bar (I think this is what you are taking about) should be 48dip each.

EDIT
I realized that is TitleBar, so probably you mean the bar with the name in B4APages.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Sub TitleBarHeight As Int Dim id As Int = nativeMe.RunMethod("TitleBarHeight", ???) - witch parameter Return id End Sub
should also be null.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Try using 'Me' as the parameter.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Calling with a Null parameter will trigger an error because the java function expects a BA ba parameter
You're right sorry I missed the ba parameter.
 
Upvote 0
Top