How to get USABLE screen width and height in Android

android, java, screen

Solution

I had the same question a while back and here is the answer that i found. Shows the activity dimensions.

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);
    }
}

Problem

I'm creating an app where I really need to know the correct screen dimensions. Actually I know how to do that... but a problem appeared, because even if you do`requestWindowFeature(Window.FEATURE_NO_TITLE);`, this: still stays on the screen and it seems, it's also counted as a part of the screen so the "screenWidth" is actually bigger, than the usable part. Isn't there any method how to get the size of the usable part and not whole screen? Or at least get the sizes of the 'scrolling thing'(but there would be a problem, that there are devices that don't show them)?

Original source

Related problems