关于 Android4.0 隐藏虚拟按键的问题 实现全屏

Android 4.0 因为项目需要, 要实现屏幕全屏,隐藏虚拟按键,即导航栏


在Android的API 中

To this day, you can hide the status bar on handsets using the FLAG_FULLSCREEN flag. In Android 4.0, the APIs that control the system bar’s visibility have been updated to better reflect the behavior of both the system bar and navigation bar:

The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.


The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.
The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required


 SYSTEM_UI_FLAG_LOW_PROFILE相当于隐藏导航栏
 SYSTEM_UI_FLAG_VISIBLE导航栏显示
 SYSTEM_UI_FLAG_HIDE_NAVIGATION要求导航栏完全隐藏-->但这对部分硬件设备有效


本人发现一个小问题:使用SYSTEM_UI_FLAG_HIDE_NAVIGATION时,会导致那个类,每个事件需要重复一次,比如:点击事件需要点击两次,滑动事件需要滑动两次。


方法:1

package com.example.button;  
  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.View;  
import android.view.Window;  
import android.view.WindowManager;  
public class MainActivity extends Activity {  
  
    Window window;  
  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  

        window = getWindow();  
        WindowManager.LayoutParams params = window.getAttributes();  
        params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE;  
        window.setAttributes(params);  

  
        setContentView(R.layout.main);  
    }  
}  


方法:2

package com.example.button;  
  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.view.Window;  
import android.view.WindowManager;  
import android.widget.Button;  
  
public class MainActivity extends Activity {  
  
    View main;  
    private Button btn;  
  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        main = getLayoutInflater().from(this).inflate(R.layout.main, null);  
  
        btn = (Button) main.findViewById(R.id.btn);  
        btn.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub  
                int i = main.getSystemUiVisibility();  
  
                if (i == View.SYSTEM_UI_FLAG_VISIBLE) {  
                    main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);  
                }  
            }  
        });  
        setContentView(main);  
    }  











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值