1

I'm write this code for set fullscreen to my activity:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
        ImageView img=(ImageView)findViewById(R.id.imageView1);
        img.setImageResource(R.drawable.tologo);
        getWindow().getDecorView().setBackgroundColor(Color.WHITE);

    }

but when i run the my app i get this error:

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content


I'm write that code from this link:
TUTORIAL

behzad razzaqi
  • 1,503
  • 2
  • 18
  • 33

2 Answers2

1

This is my solution:

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Link Full Screen Theme for AppCompat

Community
  • 1
  • 1
aletede91
  • 1,137
  • 2
  • 16
  • 30
0

Change your onCreate() method into this.

@Override
protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().getDecorView().setBackgroundColor(Color.WHITE);

    ImageView img = (ImageView) findViewById(R.id.imageView1);
    img.setImageResource(R.drawable.ic_launcher);

    setContentView(R.layout.activity_main);

}
Emil
  • 2,786
  • 20
  • 24