zoukankan      html  css  js  c++  java
  • android 设置全屏启动

    在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改! 

     设置android全屏模式有两种方法,一种是在程序代码中设置,另一种是配置manifest.xml文件,推荐使用第二种方式。 

        在manifest.xml文件中 <application>和<activity>标签中都有android:theme属性 

        只需要添加下面的xml代码就好了 

    1  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
      例如 

         下面的代码使得 ActivityDemoActivity显示为全屏模式 

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

    而下面的写法则整个应用中所有都是全屏模式 

    <?xml version="1.0" encoding="utf-8"?>  
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"        package="uni.activity"        
    android:versionCode="1"        
    android:versionName="1.0">      
    <uses-sdk android:minSdkVersion="7" />        
    <application android:icon="@drawable/icon" android:label="@string/app_name"                     android:theme="@android:style/Theme.NoTitleBar.Fullscreen">                                 
    <activity android:name=".ActivityDemoActivity" 
    android:label="@string/app_name" >              
    <intent-filter>                  
    <action android:name="android.intent.action.MAIN" />                  
    <category android:name="android.intent.category.LAUNCHER" />              </intent-filter>         
    </activity>            
    <activity android:name=".Activity01"                    android:label="@string/app_name">          
    </activity>      
    </application> 
    </manifest>  

     


    一、在代码中设置: 
       
    public class OpenGl_Lesson1 extends Activity {        
            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);        
            }        
    }    
    package com.android.tutor; 
    import android.app.Activity; 
    import android.os.Bundle; 
    import android.view.Window; 
    import android.view.WindowManager; 
    public class OpenGl_Lesson1 extends Activity { 
            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); 
            } 
    }    

    在这里要强调一点,设置全屏的俩段代码必须在setContentView(R.layout.main) 之前,不然会报错。 

  • 相关阅读:
    python pandas里面的一些函数及用法
    Python enumerate() 函数
    论文笔记:EPTD模型/ Efficient and Privacy-Preserving Truth Discovery in Mobile Crowd Sensing Systems
    论文笔记:Adversarial Attacks and Defenses in Deep Learning 对抗训练部分
    一周入门Linux 基础篇 虚拟机快照
    一周入门Linux 基础篇 虚拟机克隆
    一周入门Linux 基础篇 网络连接的三种方式
    一周入门Linux 基础篇 安装vm和Centos
    B站考研网课推荐
    关于我
  • 原文地址:https://www.cnblogs.com/dLong/p/2535955.html
Copyright © 2011-2022 走看看