На экране появляется небольшое мерцание, пока панель приложения/панель поиска скрывается, а когда веб-просмотр скрывает панель приложений/панель поиска, я хочу, чтобы такое же поведение прокрутки было у таких приложений, как приложение chrome android brwoser, веб-просмотр браузера Opera Android и панель приложений/поиска, пожалуйста, помогите, я застрял здесь последние 2 дня
вот мой Activity_browser.xml -->
и файл BrowserActivity.kt -->
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.EditText
import android.widget.ImageView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import com.google.android.material.appbar.AppBarLayout
class BrowserActivity : AppCompatActivity() {
// Revert to standard WebView
private lateinit var webView: WebView
private lateinit var appBarLayout: AppBarLayout
private lateinit var searchInput: EditText
private lateinit var clearBtn: ImageView
private lateinit var divider: View
private var isAppBarHidden = false
private var scrollThreshold = 20
private var lastScrollY = 0
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_browser)
// ================= FIND VIEWS =================
webView = findViewById(R.id.webView)
appBarLayout = findViewById(R.id.appBarLayout)
searchInput = findViewById(R.id.etSearch)
clearBtn = findViewById(R.id.btnClear)
divider = findViewById(R.id.divider)
// ================= WEBVIEW SETUP =================
webView.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
}
// IMPORTANT: Enable Nested Scrolling on the standard WebView
//webView.isNestedScrollingEnabled = true
webView.webViewClient = WebViewClient()
webView.webChromeClient = WebChromeClient()
// ================= SEARCH SETUP =================
clearBtn.setOnClickListener {
searchInput.text.clear()
}
searchInput.doAfterTextChanged {
clearBtn.visibility = if (it.isNullOrEmpty()) View.GONE else View.VISIBLE
}
// Auto Open Keyboard
searchInput.requestFocus()
searchInput.post {
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(searchInput, InputMethodManager.SHOW_IMPLICIT)
}
searchInput.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch(searchInput.text.toString())
true
} else {
false
}
}
// Expand header on click
searchInput.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
appBarLayout.setExpanded(true, true)
}
}
// ================= BACK PRESS =================
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (webView.canGoBack()) {
webView.goBack()
} else {
finish()
}
}
})
}
private fun performSearch(query: String) {
if (query.isBlank()) return
divider.visibility = View.VISIBLE
val url = if (query.startsWith("http")) {
query
} else {
"https://www.google.com/search?q=${query.trim()}"
}
webView.loadUrl(url)
webView.viewTreeObserver.addOnScrollChangedListener {
val scrollY = webView.scrollY
val dy = scrollY - lastScrollY
// ---------- SCROLL DOWN ----------
if (dy > 10 && !isAppBarHidden) {
appBarLayout.animate()
.translationY(-appBarLayout.height.toFloat())
.setDuration(200)
.start()
// IMPORTANT: pull WebView up to fill the gap
webView.animate()
.translationY(-appBarLayout.height.toFloat())
.setDuration(200)
.start()
isAppBarHidden = true
}
// ---------- SCROLL UP ----------
if (dy < -10 && isAppBarHidden) {
appBarLayout.animate()
.translationY(0f)
.setDuration(200)
.start()
webView.animate()
.translationY(0f)
.setDuration(200)
.start()
isAppBarHidden = false
}
lastScrollY = scrollY
}
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(searchInput.windowToken, 0)
searchInput.clearFocus()
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... g-and-when
На экране появляется небольшое мерцание, пока панель приложения/панель поиска скрывается, и когда веб-просмотр скрывает ⇐ Android
Форум для тех, кто программирует под Android
1768830364
Anonymous
На экране появляется небольшое мерцание, пока панель приложения/панель поиска скрывается, а когда веб-просмотр скрывает панель приложений/панель поиска, я хочу, чтобы такое же поведение прокрутки было у таких приложений, как приложение chrome android brwoser, веб-просмотр браузера Opera Android и панель приложений/поиска, пожалуйста, помогите, я застрял здесь последние 2 дня
вот мой Activity_browser.xml -->
и файл BrowserActivity.kt -->
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.EditText
import android.widget.ImageView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import com.google.android.material.appbar.AppBarLayout
class BrowserActivity : AppCompatActivity() {
// Revert to standard WebView
private lateinit var webView: WebView
private lateinit var appBarLayout: AppBarLayout
private lateinit var searchInput: EditText
private lateinit var clearBtn: ImageView
private lateinit var divider: View
private var isAppBarHidden = false
private var scrollThreshold = 20
private var lastScrollY = 0
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_browser)
// ================= FIND VIEWS =================
webView = findViewById(R.id.webView)
appBarLayout = findViewById(R.id.appBarLayout)
searchInput = findViewById(R.id.etSearch)
clearBtn = findViewById(R.id.btnClear)
divider = findViewById(R.id.divider)
// ================= WEBVIEW SETUP =================
webView.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
}
// IMPORTANT: Enable Nested Scrolling on the standard WebView
//webView.isNestedScrollingEnabled = true
webView.webViewClient = WebViewClient()
webView.webChromeClient = WebChromeClient()
// ================= SEARCH SETUP =================
clearBtn.setOnClickListener {
searchInput.text.clear()
}
searchInput.doAfterTextChanged {
clearBtn.visibility = if (it.isNullOrEmpty()) View.GONE else View.VISIBLE
}
// Auto Open Keyboard
searchInput.requestFocus()
searchInput.post {
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(searchInput, InputMethodManager.SHOW_IMPLICIT)
}
searchInput.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch(searchInput.text.toString())
true
} else {
false
}
}
// Expand header on click
searchInput.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
appBarLayout.setExpanded(true, true)
}
}
// ================= BACK PRESS =================
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (webView.canGoBack()) {
webView.goBack()
} else {
finish()
}
}
})
}
private fun performSearch(query: String) {
if (query.isBlank()) return
divider.visibility = View.VISIBLE
val url = if (query.startsWith("http")) {
query
} else {
"https://www.google.com/search?q=${query.trim()}"
}
webView.loadUrl(url)
webView.viewTreeObserver.addOnScrollChangedListener {
val scrollY = webView.scrollY
val dy = scrollY - lastScrollY
// ---------- SCROLL DOWN ----------
if (dy > 10 && !isAppBarHidden) {
appBarLayout.animate()
.translationY(-appBarLayout.height.toFloat())
.setDuration(200)
.start()
// IMPORTANT: pull WebView up to fill the gap
webView.animate()
.translationY(-appBarLayout.height.toFloat())
.setDuration(200)
.start()
isAppBarHidden = true
}
// ---------- SCROLL UP ----------
if (dy < -10 && isAppBarHidden) {
appBarLayout.animate()
.translationY(0f)
.setDuration(200)
.start()
webView.animate()
.translationY(0f)
.setDuration(200)
.start()
isAppBarHidden = false
}
lastScrollY = scrollY
}
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(searchInput.windowToken, 0)
searchInput.clearFocus()
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79871235/a-small-flicker-in-screen-is-coming-while-appbar-searchbar-is-hiding-and-when[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия