Android开发学习笔记之窗口操作

来源:互联网 发布:nodejs java性能对比 编辑:程序博客网 时间:2024/06/05 18:57

//隐藏标题

requestWindowFeature(Window.FEATURE_NO_TITLE);


//应用运行时,保持屏幕高亮,不锁屏

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


//设置全屏

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);


//取消全屏

final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);


//检测竖屏还是横屏

public void onConfigurationChanged(Configuration newConfig)

{

if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)

{

}

else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)

{

}

}


//设置竖屏、横屏

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);



//获取屏幕宽和高

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int mWidth = dm.widthPixels;
int mHeight = dm.heightPixels;

0 0
原创粉丝点击