Fullscreen fuer WebView eingebaut, so das die NaviBar auch mit verschwindet.

This commit is contained in:
Steffen Probst 2021-11-23 21:27:00 +01:00
parent 9fe4cf5a23
commit 04c6c43e47
5 changed files with 54 additions and 11 deletions

View File

@ -3,22 +3,35 @@
package="com.example.app" package="com.example.app"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<supports-screens
android:xlargeScreens="true"
android:largeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:fullBackupContent="true" android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:fitsSystemWindows="true"
tools:ignore="GoogleAppIndexingWarning"> tools:ignore="GoogleAppIndexingWarning">
<activity <activity
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize|keyboardHidden"
android:name="com.example.app.MainActivity" android:name="com.example.app.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:exported="true"> android:exported="true"
android:launchMode = "singleInstance"
android:keepScreenOn="true"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>

View File

@ -3,6 +3,8 @@ package com.example.app;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
@ -14,6 +16,16 @@ public class MainActivity extends Activity {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//Code fuer Fullscreen in APP
//http://www.java2s.com/example/java-api/android/view/view/system_ui_flag_fullscreen-4.html
getWindow().getDecorView()// w w w . j a v a2 s. c o m
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//Code Ende fuer Fullscreen
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview); mWebView = findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings(); WebSettings webSettings = mWebView.getSettings();
@ -21,7 +33,7 @@ public class MainActivity extends Activity {
mWebView.setWebViewClient(new MyWebViewClient()); mWebView.setWebViewClient(new MyWebViewClient());
// REMOTE RESOURCE // REMOTE RESOURCE
// mWebView.loadUrl("https://example.com"); mWebView.loadUrl("https://foto.steffen.probst.click/index.php?/category/8#&ui-state=dialog");
// LOCAL RESOURCE // LOCAL RESOURCE
// mWebView.loadUrl("file:///android_asset/index.html"); // mWebView.loadUrl("file:///android_asset/index.html");

View File

@ -1,5 +1,8 @@
package com.example.app; package com.example.app;
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.webkit.WebView; import android.webkit.WebView;
@ -12,13 +15,14 @@ class MyWebViewClient extends WebViewClient {
String hostname; String hostname;
// YOUR HOSTNAME // YOUR HOSTNAME
hostname = "example.com"; hostname = "foto.steffen.probst.click";
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith(hostname)) { if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith(hostname)) {
return false; return false;
} }
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent); view.getContext().startActivity(intent);
return true; return true;
} }

View File

@ -5,7 +5,7 @@
<WebView <WebView
android:id="@+id/activity_main_webview" android:id="@+id/activity_main_webview"
android:layout_width="match_parent" android:layout_width="fill_parent"
android:layout_height="match_parent" /> android:layout_height="fill_parent" />
</RelativeLayout> </RelativeLayout>

View File

@ -1,9 +1,23 @@
<resources> <resources>
<!--
<style name="AppTheme" parent="android:Theme.DeviceDefault.Light"> <style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:statusBarColor">@android:color/black</item> <item name="android:statusBarColor">@android:color/black</item>
<item name="android:windowActionBar">false</item> <item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style> -->
<!-- <style name="AppTheme" parent="android:Theme.Material.Wallpaper.NoTitleBar"> -->
<style name="AppTheme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:enforceNavigationBarContrast">false</item>
</style> </style>
</resources> </resources>