在 kivy 中关闭 webview
close webview in kivy
我正在尝试关闭或销毁 webview 并显示其他布局
这是我的 webview 代码,如果不可能,我想获取当前页面的 link,如果当前页面 link 等于某些 link,我想退出webview 请帮我解决这个问题
from android.runnable import run_on_ui_thread as run_thread
from jnius import autoclass
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.app import runTouchApp
from kivy.clock import Clock, mainthread
@mainthread
def quit_screen():
app = App.get_running_app()
e=GridLayout()
d1=button(text="hi end")
e.add_widget(e)
app.root.switch_screen(e)
@run_thread
def key_back_handler():
webview.loadUrl("about:blank")
webview.clearHistory()
webview.clearCache(True)
webview.clearFormData()
webview.freeMemory()
Clock.schedule_once(quit_screen, 0)
@run_thread
def WebView(link,*args):
WebV = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity
webview = WebV(activity)
settings = webview.getSettings()
settings.setJavaScriptEnabled(True)
settings.setUseWideViewPort(True)
settings.setLoadWithOverviewMode(True)
settings.setSupportZoom(True)
settings.setBuiltInZoomControls(True)
wvc = WebViewClient()
webview.setWebViewClient(wvc)
activity.setContentView(webview)
webview.loadUrl(link)
m=GridLayout(cols=1,rows=1)
d=GridLayout(cols=1,rows=1)
m.add_widget(d)
def Push(butoon):
WebView("https://www.google.com")
b=Button(text="hi")
b.bind(on_press=Push)
d.add_widget(b)
runTouchApp(m).run()
像这样,但它没有在 android
上按下后关闭
提前感谢您的帮助
诀窍是将 Webview 放入 Kivy ModalView 并从 Java 返回 button/gesture 以退出 ModalView ,例如:
https://github.com/RobertFlatt/Android-for-Python/tree/main/webview
我正在尝试关闭或销毁 webview 并显示其他布局 这是我的 webview 代码,如果不可能,我想获取当前页面的 link,如果当前页面 link 等于某些 link,我想退出webview 请帮我解决这个问题
from android.runnable import run_on_ui_thread as run_thread
from jnius import autoclass
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.app import runTouchApp
from kivy.clock import Clock, mainthread
@mainthread
def quit_screen():
app = App.get_running_app()
e=GridLayout()
d1=button(text="hi end")
e.add_widget(e)
app.root.switch_screen(e)
@run_thread
def key_back_handler():
webview.loadUrl("about:blank")
webview.clearHistory()
webview.clearCache(True)
webview.clearFormData()
webview.freeMemory()
Clock.schedule_once(quit_screen, 0)
@run_thread
def WebView(link,*args):
WebV = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity
webview = WebV(activity)
settings = webview.getSettings()
settings.setJavaScriptEnabled(True)
settings.setUseWideViewPort(True)
settings.setLoadWithOverviewMode(True)
settings.setSupportZoom(True)
settings.setBuiltInZoomControls(True)
wvc = WebViewClient()
webview.setWebViewClient(wvc)
activity.setContentView(webview)
webview.loadUrl(link)
m=GridLayout(cols=1,rows=1)
d=GridLayout(cols=1,rows=1)
m.add_widget(d)
def Push(butoon):
WebView("https://www.google.com")
b=Button(text="hi")
b.bind(on_press=Push)
d.add_widget(b)
runTouchApp(m).run()
像这样,但它没有在 android
提前感谢您的帮助
诀窍是将 Webview 放入 Kivy ModalView 并从 Java 返回 button/gesture 以退出 ModalView ,例如:
https://github.com/RobertFlatt/Android-for-Python/tree/main/webview