public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//无title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//全屏
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
WindowManager.LayoutParams. FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
其中requestWindowFeature和getWindow().setFlags必须一起使用,并且在setContentView前面
3、解决屏幕方向改变Activity销毁重建问题
当屏幕方向改变时,经常发现刚输入的文字被清空了、imageView图片不存在了,或是网络数据重新获取,其实是Activity会被销毁,重新调用OnCreate构建,如何防止这种情况呢,分为两步:
3.1 在AndroidManifest.xml中对Activity属性进行设置,如下:
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:theme ="@style/update_status_style">
android:configChanges=”orientation|keyboardHidden”表示改变界面方向和隐藏键盘
具体android:configChanges见configChanges
3.2 重载onConfigurationChanged方法,此方法会在屏幕方向改变时被调用如下:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 加入横屏要处理的代码
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
// 加入竖屏要处理的代码
}