Monday, 30 September 2013

Set an activity as full screen in Android

Sometimes because the size of the screen, the app should goes full screen in order to allow the user to see the maximum details possible.

For those cases, the follow code works great:

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

Just one small things to remember.
If you are using the action bar and there is a method called getSupportActionBar(), for example:

getSupportActionBar().setHomeButtonEnabled(true);

This will cause Null Pointer Exception because the app has disable the action bar. In this case, don't use the follow code:

requestWindowFeature(Window.FEATURE_NO_TITLE);

Source:

No comments:

Post a Comment