diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 58d6094da..24bfe161d 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -86,4 +86,8 @@ class App : MultiDexApplication() { } } + companion object { + var navigationBarHeight = 0 + } + } diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index deb4a5f62..8f4105882 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -12,6 +12,7 @@ import android.view.View import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity import androidx.viewbinding.ViewBinding +import io.legado.app.App import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey @@ -99,6 +100,13 @@ abstract class BaseActivity( observeLiveBus() } + override fun onWindowFocusChanged(hasFocus: Boolean) { + super.onWindowFocusChanged(hasFocus) + if (hasFocus) { + App.navigationBarHeight = navigationBarHeight + } + } + override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: Configuration?) { super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig) findViewById(R.id.title_bar) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 739c53ab2..0e0152540 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -7,7 +7,6 @@ import android.content.res.Configuration import android.os.Bundle import android.os.Handler import android.os.Looper -import android.util.Log import android.view.* import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.activity.result.contract.ActivityResultContracts @@ -151,7 +150,6 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) - Log.d("navigationBarHeight", navigationBarHeight.toString()) upSystemUiVisibility() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 73fe4ca0c..85c37d61d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -7,6 +7,7 @@ import android.view.LayoutInflater import android.widget.FrameLayout import androidx.core.view.isGone import androidx.core.view.isInvisible +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.constant.AppConst.timeFormat @@ -86,7 +87,7 @@ class PageView(context: Context) : FrameLayout(context) { pageNvBar.layoutParams = pageNvBar.layoutParams.apply { height = if (it.hideNavigationBar) 0 - else activity?.navigationBarHeight ?: 0 + else App.navigationBarHeight } } contentTextView.upVisibleRect()