我是Java和Android的新手,所以我从网上粘贴了代码。目标是为一个网页创建一个简单的Web浏览器。在该网页中,可以编辑文本等。
主要目标是使浏览器保持全屏,以便远离android导航按钮。
我尝试使用此代码,但直到知道才成功。 Detecting Soft Keyboard Hidden State
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MyActivity";
static int mAppHeight;
static int currentOrientation = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE);
setContentView(R.layout.activity_main);
//make a webview object
WebView webview=new WebView(this);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE);
}
});
// enable javascript
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
//show it through setcontentview()method
setContentView(webview);
webview.loadUrl("https://www.mypage.com");
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE);
}
}
有人可以帮助从链接中放置代码吗?
非常感谢 问候
编辑:
我也尝试过此操作,但是在显示或隐藏软键盘时我看不到事件运行。:https://github.com/yshrsmz/KeyboardVisibilityEvent
答案 0 :(得分:0)
尝试:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
答案 1 :(得分:0)
在清单中使用-
<activity
android:name=".Activities. MainActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
</activity>
在Activity onCreate中仅使用此-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout. activity_main);
并删除
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE);
setContentView(R.layout.activity_main);