How to set activity to fullscreen mode in Android? [duplicate]

时间秒杀一切 提交于 2019-11-28 22:23:13

问题


How to set full screen mode for activity in Android? I am using the following code to set full screen but it generates an error:

Exception:

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

Code:

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

回答1:


please check the code

public 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.main);
}

and note it is set before setting the content view




回答2:


try this in AndroidManifest:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>



回答3:


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



回答4:


put requestWindowFeature first in your code....like this...

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


来源:https://stackoverflow.com/questions/12388771/how-to-set-activity-to-fullscreen-mode-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!