先来看一个android屏幕全屏实现代码
代码如下 | 复制代码 |
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); setContentView(R.layout.newslists); newsListLayout = findViewById(R.id.newslistlayout); newsListLayout.setBackgroundColor(Color.MAGENTA); newsNameList = (ListView) findViewById(R.id.newsnamelist); showPage = (TextView) findViewById(R.id.newslistshowpage); |
现在我们还可以来判断是全屏或非全屏
代码如下 | 复制代码 |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); int v = this.getWindow().getAttributes().flags; // 全屏 66816 - 非全屏 65792 if(v != 66816){//非全屏 this.getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }else{//取消全屏 this.getWindow().clearFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN); } } |
时间: 2024-10-23 10:31:17