Commit 97eceac0 authored by wanglei's avatar wanglei

...

parent 0eebeedd
......@@ -2,6 +2,9 @@ package com.base.browserwhite.ui.activity.webbrowser
import android.graphics.Color
import android.view.KeyEvent
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import androidx.activity.addCallback
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
......@@ -46,6 +49,17 @@ class WebBrowserActivity : BaseActivity<ActivityWebBrowserBinding>() {
} else {
binding.ivRight.setImageResource(R.mipmap.right_n)
}
binding.editWeb.setOnEditorActionListener(object : TextView.OnEditorActionListener {
override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
if (actionId == EditorInfo.IME_ACTION_DONE) {
val url = v.toString()
currentFragment?.jumpUrl(url)
return true; // 返回true表示事件已处理
}
return false
}
})
}
override fun initListener() {
......
......@@ -12,15 +12,17 @@ import android.webkit.WebStorage
import android.webkit.WebView
import android.webkit.WebViewClient
import com.base.browserwhite.databinding.FragmentWebViewBinding
import com.base.browserwhite.utils.LogEx
class WebViewFragment(val uri: String) : BaseFragment<FragmentWebViewBinding>() {
private val TAG = "WebViewFragment"
override val binding: FragmentWebViewBinding by lazy {
FragmentWebViewBinding.inflate(layoutInflater)
}
var onPageFinished: ((uri:String?) -> Unit)? = null
var onPageFinished: ((uri: String?) -> Unit)? = null
override fun setView() {
......@@ -61,6 +63,7 @@ class WebViewFragment(val uri: String) : BaseFragment<FragmentWebViewBinding>()
//设置WebChromeClient
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
// LogEx.logDebug(TAG, )
}
override fun onReceivedTitle(view: WebView?, title: String?) {
......@@ -123,4 +126,8 @@ class WebViewFragment(val uri: String) : BaseFragment<FragmentWebViewBinding>()
binding.webView.evaluateJavascript("window.history.back();", null)
}
fun jumpUrl(url: String) {
binding.webView.loadUrl(url)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景色 -->
<item
android:id="@android:id/background"
android:drawable="@drawable/bg_progress_web" />
<!-- 设置进度条颜色 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#0571ED" />
</shape>
</clip>
</item>
</layer-list>
\ No newline at end of file
......@@ -97,7 +97,6 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginVertical="15dp"
app:layout_constraintBottom_toTopOf="@id/cl_bottom"
app:layout_constraintTop_toBottomOf="@id/cl_top"
tools:ignore="UselessLeaf" />
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.fragment.WebViewFragment">
<ProgressBar
android:id="@+id/progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/progress_bar_web" />
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment