Android Question "Real" Screen Height

ArminKH

Well-Known Member
I realized that this is not essential for "my" problem.

However, knowing the height of the system bar may be useful, who knows.
to know status bar height try attached lib.from here http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels?lq=1
this is compiled code:
B4X:
package ir.arminkh.screenrealsize;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;


@ShortName("ScreenRealSize")
@Version(1.00f)
@Author("ArminKH")
public class ScreenRealSize {
   
    public int getStatusBarHeight(BA ba){
        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;
    }


   
   
}
 

Attachments

  • ScreenRealSize.jar
    851 bytes · Views: 276
  • ScreenRealSize.xml
    642 bytes · Views: 367
Upvote 0

ArminKH

Well-Known Member
try attached lib(has a better name:D)..from here http://stackoverflow.com/questions/...-and-width-of-navigation-bar-programmatically
as my device has not navigation bar so i cant test it.
B4X:
package ir.arminkh.screencomponentsize;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;


@ShortName("ScreenComponentSize")
@Version(1.00f)
@Author("ArminKH")
public class ScreenComponentSize {
   
    public int getStatusBarHeight(BA ba){
        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 getNavigationBarHeight(BA ba){
        int result = 0;
        int resId = BA.applicationContext.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resId > 0) {
            result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
        }
        return result;       
    }
   
}
 

Attachments

  • ScreenComponentSize.jar
    915 bytes · Views: 302
  • ScreenComponentSize.xml
    947 bytes · Views: 368
Upvote 0

ArminKH

Well-Known Member
It works perfectly, thank you, Armin.

Maybe can you add getTitleBarHeight?
It should be equal to Status Bar, however.
yes,if i can find a good solution with java code for this one i'll post here
 
Upvote 0

ArminKH

Well-Known Member
attached is based on your link and i'm not sure about it
also it's using @ActivityObject anotation
B4X:
package ir.arminkh.screencomponentsize;

import android.graphics.Rect;
import android.view.Window;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;


@ShortName("ScreenComponentSize")
@Version(1.00f)
@Author("ArminKH")
@ActivityObject
public class ScreenComponentSize {
  
    private int StatusBarHeight(BA ba) {
        Rect r = new Rect();
        Window w = ba.activity.getWindow();
        w.getDecorView().getWindowVisibleDisplayFrame(r);
        return r.top;
    }
   
     /**
     * Height of the title bar  
     */
    public int TitleBarHeight(BA ba) {
        int viewTop = ba.activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
        return (viewTop - StatusBarHeight(ba));
    }
  
  
  
    /**
     * Height of the status bar  
     */
    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;
    }

    /**
     * Height of the bottom navigation / system bar
     */
    public int NavigationBarHeight(){
        int result = 0;
        int resId = BA.applicationContext.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resId > 0) {
            result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
        }
        return result;      
    }
  

    /**
     * Height of the bottom navigation bar in portrait; often the same as @dimen/navigation_bar_height
     */
    public int NavigationBarHeightLandscape(){
        int result = 0;
        int resId = BA.applicationContext.getResources().getIdentifier("navigation_bar_height_landscape", "dimen", "android");
        if (resId > 0) {
            result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
        }
        return result;      
    }  
  
  

    /**
     * Default height of an action bar
     */
    public int ActionBarDefaultHeight(){
        int result = 0;
        int resId = BA.applicationContext.getResources().getIdentifier("action_bar_default_height", "dimen", "android");
        if (resId > 0) {
            result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
        }
        return result;  
    }
}



//
maybe we need to check our code by erel
 

Attachments

  • ScreenComponentSize.xml
    1.5 KB · Views: 425
  • ScreenComponentSize.jar
    1.3 KB · Views: 338
Upvote 0
Top