Android 4.2虚拟按键背景透明,Android 4.0 隐藏虚拟按键(导航栏)的方法

在Android4.0里,多了一些API,其中包括怎样隐藏虚拟按键(导航栏),这样编写游戏或一个视频播放器时,可以设置隐藏虚拟按键的参数,达到最佳效果,当然前提是使用的手机是有虚拟按键的,例如galaxy nexus(i9250)。好吧,看一看官方的Android4.0 api说明就明白了。

Controls for system UI visibility

Since the early days of Android, the system has managed a UI component known as the status bar, which resides at the top of handset devices to deliver information such as the carrier signal, time, notifications, and so on. Android 3.0 added the system bar for tablet devices, which resides at the bottom of the screen to provide system navigation controls (Home, Back, and so forth) and also an interface for elements traditionally provided by the status bar. In Android 4.0, the system provides a new type of system UI called the navigation bar. You might consider the navigation bar a re-tuned version of the system bar designed for handsets—it provides navigation controls for devices that don’t have hardware counterparts for navigating the system, but it leaves out the system bar's notification UI and setting controls. As such, a device that provides the navigation bar also has the status bar at the top.

To this day, you can hide the status bar on handsets using the

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 STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.

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.

You can set each of these flags for the system bar and navigation bar by calling

To synchronize other events in your activity with visibility changes to the system UI (for example, hide the action bar or other UI controls when the system UI hides), you should register a

See the OverscanActivity class for a demonstration of different system UI options.

看完后,写个测试例子试一下,Ok~

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

public class HideTestActivity extends Activity implements OnClickListener{

View main ;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

main = getLayoutInflater().from(this).inflate(R.layout.main, null);

main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

main.setOnClickListener(this);

setContentView(main);

}

@Override

public void onClick(View v) {

int i = main.getSystemUiVisibility();

if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {

main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

} else if (i == View.SYSTEM_UI_FLAG_VISIBLE){

main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

} else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) {

main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值