How to get USABLE screen width and height in Android

I am creating an application where I really need to know the correct screen sizes. Actually, I know how to do this ... but the problem has arisen, because even if you do requestWindowFeature(Window.FEATURE_NO_TITLE);, it is:enter image description here

still remains on the screen, and it looks like it is also considered part of the screen, so the "screenWidth" is actually more than the useful part.

Is there no way to get the size of the useful part, not the entire screen? Or at least get the sizes of the "scroll" (but there will be a problem that there are devices that do not show them)?

+4
source share
2 answers

, , . .

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.graphics.Point;

public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main)

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        int width = size.x;
        int height = size.y;

        //Set two textViews to display the width and height
        //ex: txtWidth.setText("X: " + width);
    }
}
+4
+1

Source: https://habr.com/ru/post/1543077/


All Articles