第1个回答 2016-05-21
Android 隐藏虚拟按键,可以使用谷歌官方提供的api里的SYSTEM_UI_FLAG_HIDE_NAVIGATION 这个标志位来完成,如下代码:
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);//设置虚拟键隐藏
}
}
}