• (转) Android 全屏控制:动态切换全屏和非全屏


    转自:http://blog.csdn.net/michaelpp/article/details/7302308

    动态切换全屏和非全屏:

    package com.screen;  
     
    import android.app.Activity;  
    import android.os.Bundle;  
    import android.view.View;  
    import android.view.WindowManager;  
    import android.view.View.OnClickListener;  
    import android.widget.Button;  
     
     public class MainActivity extends Activity {  
          
        private boolean isFulllScreen = false;  
        private Button button;  
          
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  
            button = (Button)findViewById(R.id.button);  
            button.setOnClickListener(new OnClickListener() {  
                  
                @Override  
                public void onClick(View v) {  
                    isFulllScreen = !isFulllScreen;  
                    if (isFulllScreen) {  
                        button.setText(getResources().getText(R.string.exit_full_screen));  
                        WindowManager.LayoutParams params = getWindow().getAttributes();  
                        params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;  
                        getWindow().setAttributes(params);  
                        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);  
                    } else {  
                        button.setText(getResources().getText(R.string.full_screen));  
                        WindowManager.LayoutParams params = getWindow().getAttributes();  
                        params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);  
                        getWindow().setAttributes(params);  
                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);  
                    }  
                }  
            });  
              
        }  
    }  

    非动态的全屏设置:

    在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果。其一,通过在代码中可以设置,其二,通过manifest配置文件来设置全屏。


          其一:在代码中设置(如下)


    view plaincopy to clipboardprint?
    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);  
    }  
     
           但要注意的是:在代码中设置的话,设置无标题和设置全屏的两段代码要放置在 setContentView(R.layout.main); 这段代码的前面。要不然会报错。


           其二:在manifest配置文件中设置


    view plaincopy to clipboardprint?
    <?xml version="1.0" encoding="utf-8"?>  
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
          package="com.andyidea"  
          android:versionCode="1"  
          android:versionName="1.0">  
        <uses-sdk android:minSdkVersion="8" />  
        <application android:icon="@drawable/icon" android:label="@string/app_name">  
            <activity android:name=".login.LoginActivity"   
                      android:theme="@android:style/android.NoTitleBar.Fullscreen"  
                      android:label="@string/app_name">  
                <intent-filter>  
                    <action android:name="android.intent.action.MAIN" />  
                    <category android:name="android.intent.category.LAUNCHER" />  
                </intent-filter>  
            </activity>  
        </application>  
    </manifest>  
     
            在相应的Activity中节点中添加属性:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 即可以设置某个Activity全屏显示。若设置成 android:theme="@android:style/Theme.NoTitleBar" 即是只是设置成无标题状态。

    在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果。其一,通过在代码中可以设置,其二,通过manifest配置文件来设置全屏。


          其一:在代码中设置(如下)


    view plaincopy to clipboardprint?
    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);  
    }  
     
           但要注意的是:在代码中设置的话,设置无标题和设置全屏的两段代码要放置在 setContentView(R.layout.main); 这段代码的前面。要不然会报错。


           其二:在manifest配置文件中设置


    view plaincopy to clipboardprint?
    <?xml version="1.0" encoding="utf-8"?>  
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
          package="com.andyidea"  
          android:versionCode="1"  
          android:versionName="1.0">  
        <uses-sdk android:minSdkVersion="8" />  
        <application android:icon="@drawable/icon" android:label="@string/app_name">  
            <activity android:name=".login.LoginActivity"   
                      android:theme="@android:style/android.NoTitleBar.Fullscreen"  
                      android:label="@string/app_name">  
                <intent-filter>  
                    <action android:name="android.intent.action.MAIN" />  
                    <category android:name="android.intent.category.LAUNCHER" />  
                </intent-filter>  
            </activity>  
        </application>  
    </manifest>  
     
            在相应的Activity中节点中添加属性:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 即可以设置某个Activity全屏显示。若设置成 android:theme="@android:style/Theme.NoTitleBar" 即是只是设置成无标题状态。
  • 相关阅读:
    百分点零售行业大数据解决方案
    百分点用户标签管理系统
    百分点个性化系统解决方案
    百分点数据洞察系统解决方案
    来学学数据分析吧(二)第一章 预测和关联数量特征
    来学学数据分析吧(一)
    生产者和消费者问题学习以及Java实现
    java中的双重锁定检查(Double Check Lock)
    python学习(十四)面向对象
    python学习(十二)模块
  • 原文地址:https://www.cnblogs.com/ren-gh/p/4058974.html
Copyright © 2020-2023  润新知