package com.example.viewexcercises;
import android.os.Bundle;
import android.view.View;
import android.R.layout;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity implements View.OnClickListener,View.OnSystemUiVisibilityChangeListener{
private View main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
main=getLayoutInflater().inflate(R.layout.activity_main,null);
setContentView(main);
main.setOnClickListener(this);
//刚开始为可见状态,也是默认状态
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onSystemUiVisibilityChange(int visibility) {
// TODO Auto-generated method stub
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int status=main.getSystemUiVisibility();
if (status==View.SYSTEM_UI_FLAG_LOW_PROFILE) {
//虚拟按键将被隐藏,且不占空间
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
else if(status==View.SYSTEM_UI_FLAG_HIDE_NAVIGATION){
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
else if (status==View.SYSTEM_UI_FLAG_VISIBLE) {
//虚拟按键被隐藏,但占一定空间
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}
}
隐藏虚拟按键的实现
最新推荐文章于 2024-02-01 16:50:32 发布