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 881323bc6..96d3d21d5 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -41,7 +41,7 @@ abstract class BaseActivity(private val layoutID: Int, private val fullScreen: B final override fun onCreateOptionsMenu(menu: Menu?): Boolean { return menu?.let { val bool = onCompatCreateOptionsMenu(it) - it.setIconColor(this) + it.applyTint(this) bool } ?: super.onCreateOptionsMenu(menu) } diff --git a/app/src/main/java/io/legado/app/base/BaseFragment.kt b/app/src/main/java/io/legado/app/base/BaseFragment.kt index f8314c44c..1f3ff2dcb 100644 --- a/app/src/main/java/io/legado/app/base/BaseFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseFragment.kt @@ -6,7 +6,7 @@ import android.view.MenuItem import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment -import io.legado.app.utils.setIconColor +import io.legado.app.utils.applyTint import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.MainScope import kotlinx.coroutines.cancel @@ -31,7 +31,7 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID), supportToolbar?.let { it.menu.apply { onCompatCreateOptionsMenu(this) - setIconColor(requireContext()) + applyTint(requireContext()) } it.setOnMenuItemClickListener { item -> diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index e59d87149..512b2ffa7 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -178,7 +178,7 @@ object ATH { } } - fun applyTint(view: View?) { + fun applyAccentTint(view: View?) { view?.apply { setTint(this, context.accentColor) } diff --git a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt index dd727063a..0ab6fcfc4 100644 --- a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt @@ -147,7 +147,13 @@ object TintHelper { is SwitchCompat -> setTint(view, color, isDark) is SearchView -> { val iconIdS = - intArrayOf(androidx.appcompat.R.id.search_button, androidx.appcompat.R.id.search_close_btn) + intArrayOf( + androidx.appcompat.R.id.search_button, + androidx.appcompat.R.id.search_close_btn, + androidx.appcompat.R.id.search_go_btn, + androidx.appcompat.R.id.search_voice_btn, + androidx.appcompat.R.id.search_mag_icon + ) for (iconId in iconIdS) { val icon = view.findViewById(iconId) if (icon != null) { diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index 36305d870..3486589a8 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -19,6 +19,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.BookSource import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.utils.getViewModel @@ -94,6 +95,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun initSearchView() { + ATH.setTint(search_view, primaryTextColor) search_view.onActionViewExpanded() search_view.queryHint = getString(R.string.search_book_source) search_view.clearFocus() diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index b253d5c72..e77642729 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -9,6 +9,8 @@ import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_chapter_list.* @@ -30,6 +32,7 @@ class ChapterListActivity : BaseActivity(R.layout.activity_chapter_list) { menuInflater.inflate(R.menu.search_view, menu) val search = menu.findItem(R.id.action_search) searchView = search.actionView as SearchView + ATH.setTint(searchView!!, primaryTextColor) searchView?.maxWidth = resources.displayMetrics.widthPixels searchView?.onActionViewCollapsed() searchView?.setOnCloseListener { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 5ff3135a8..06ebcdc77 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -29,7 +29,6 @@ import io.legado.app.ui.search.SearchActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_edittext.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* -import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.textColor @@ -135,7 +134,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b customView { layoutInflater.inflate(R.layout.dialog_edittext, null).apply { editText = edit_view.apply { - ATH.applyTint(this) + ATH.applyAccentTint(this) hint = "分组名称" } } diff --git a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt index 1730b9d34..1b19f5b1d 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt @@ -13,6 +13,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.SearchShow import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_search.* import kotlinx.android.synthetic.main.view_search.* @@ -32,6 +33,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_search) } private fun initSearchView() { + ATH.setTint(search_view, primaryTextColor) search_view.onActionViewExpanded() search_view.isSubmitButtonEnabled = true search_view.queryHint = getString(R.string.search_book_key) diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 7e57837b4..796e6fcb3 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -145,10 +145,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a override fun onAttachedToWindow() { super.onAttachedToWindow() - if (attachToActivity) { - attachToActivity() - } - wrapTheme() + attachToActivity() } fun setNavigationOnClickListener(clickListener: ((View) -> Unit)) { @@ -179,7 +176,14 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a toolbar.setSubtitleTextAppearance(context, resId) } - private fun wrapTheme() { + private fun attachToActivity() { + if(attachToActivity) { + activity?.let { + it.setSupportActionBar(toolbar) + it.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUp) + } + } + val primaryTextColor = if (isInEditMode) Color.BLACK else context.primaryTextColor DrawableUtils.setTint(toolbar.overflowIcon, primaryTextColor) toolbar.setTitleTextColor(primaryTextColor) @@ -191,13 +195,6 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a } } - private fun attachToActivity() { - activity?.let { - it.setSupportActionBar(toolbar) - it.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUp) - } - } - private fun wrapDrawableTint(drawable: Drawable?, tintList: ColorStateList?, tintMode: Int) { if (drawable == null || tintList == null) return val wrappedDrawable = DrawableCompat.wrap(drawable.mutate()) diff --git a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt index 8d97321af..21eeae968 100644 --- a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt @@ -10,7 +10,7 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.primaryTextColor -fun Menu.setIconColor(context: Context): Menu = this.let { menu -> +fun Menu.applyTint(context: Context): Menu = this.let { menu -> if (menu is MenuBuilder) { menu.setOptionalIconsVisible(true) }