pull/169/head
yangyxd 5 years ago
parent 1ece88762e
commit b758beaf09
  1. 5
      app/src/main/java/io/legado/app/base/BaseFragment.kt
  2. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 7
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt
  4. 23
      app/src/main/java/io/legado/app/utils/UIUtils.kt
  5. 12
      app/src/main/res/drawable/ic_groups.xml
  6. 9
      app/src/main/res/drawable/ic_groups_menu.xml
  7. 2
      app/src/main/res/menu/main_bookshelf.xml

@ -6,7 +6,11 @@ import android.view.*
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.utils.UIUtils
import io.legado.app.utils.applyTint
import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@ -52,6 +56,7 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID),
supportToolbar?.let {
it.menu.apply {
onCompatCreateOptionsMenu(this)
UIUtils.setToolbarMoreIconCustomColor(toolbar, UIUtils.getMenuColor(requireContext()))
applyTint(requireContext())
}

@ -61,7 +61,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
setSupportToolbar(toolbar)
initView()
initBookGroupData()
UIUtils.setToolbarMoreIconCustomColor(toolbar)
}
override fun onCompatCreateOptionsMenu(menu: Menu) {

@ -19,13 +19,8 @@ fun Menu.applyTint(context: Context, theme: Theme = Theme.Auto): Menu = this.let
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}
val primaryTextColor = context.primaryTextColor
val defaultTextColor = context.getCompatColor(R.color.tv_text_default)
val tintColor = when (theme) {
Theme.Dark -> context.getCompatColor(R.color.md_white_1000)
Theme.Light -> context.getCompatColor(R.color.md_black_1000)
else -> primaryTextColor
}
val tintColor = UIUtils.getMenuColor(context, theme)
menu.forEach { item ->
(item as MenuItemImpl).let { impl ->
//overflow:展开的item

@ -1,27 +1,42 @@
package io.legado.app.utils
import android.graphics.ColorFilter
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Build
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.primaryTextColor
@Suppress("unused")
object UIUtils {
/** 设置更多工具条图标和颜色 */
fun setToolbarMoreIconCustomColor(toolbar: Toolbar, colorId: Int? = null) {
fun setToolbarMoreIconCustomColor(toolbar: Toolbar, color: Int? = null) {
if (toolbar == null)
return
val moreIcon = ContextCompat.getDrawable(toolbar.context, R.drawable.ic_more)
if(moreIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (colorId != null ) {
moreIcon.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(toolbar.context, colorId), PorterDuff.Mode.SRC_ATOP)
if (color != null ) {
moreIcon.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
}
toolbar.overflowIcon = moreIcon
}
}
fun getMenuColor(context: Context, theme: Theme = Theme.Auto, requiresOverflow: Boolean = false): Int {
val defaultTextColor = context.getCompatColor(R.color.tv_text_default)
if (requiresOverflow)
return defaultTextColor
val primaryTextColor = context.primaryTextColor
return when (theme) {
Theme.Dark -> context.getCompatColor(R.color.md_white_1000)
Theme.Light -> context.getCompatColor(R.color.md_black_1000)
else -> primaryTextColor
}
}
}

@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="24">
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M32,9L32,5a1,1 0,0 0,-1 -1L22.15,4a1,1 0,0 0,-1 1L21.15,6.25L17,6.25a1,1 0,0 0,-1 1v9.5a1,1 0,0 0,1 1h4.19L21.19,19a1,1 0,0 0,1 1L31,20a1,1 0,0 0,1 -1L32,15a1,1 0,0 0,-1 -1L22.15,14a1,1 0,0 0,-1 1v1.25L17.48,16.25L17.48,7.75h3.69L21.17,9a1,1 0,0 0,1 1L31,10A1,1 0,0 0,32 9ZM22.65,5.5h7.87v3L22.65,8.5ZM22.65,15.5h7.87v3L22.65,18.5Z"
android:fillColor="#3f3f3f"/>
android:fillColor="#FF000000"
android:pathData="M15,0L6.15,0a1,1 0,0 0,-1 1L5.15,2.25L1,2.25a1,1 0,0 0,-1 1v9.5a1,1 0,0 0,1 1L5.17,13.75L5.17,15a1,1 0,0 0,1 1L15,16a1,1 0,0 0,1 -1L16,11a1,1 0,0 0,-1 -1L6.15,10a1,1 0,0 0,-1 1v1.25L1.48,12.25L1.48,3.75L5.17,3.75L5.17,5a1,1 0,0 0,1 1L15,6a1,1 0,0 0,1 -1L16,1a1,1 0,0 0,-1 -1ZM6.65,4.5v-3h7.87v3ZM6.65,14.5v-3h7.87v3Z"/>
</vector>

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="24">
<path
android:pathData="M32,9L32,5a1,1 0,0 0,-1 -1L22.15,4a1,1 0,0 0,-1 1L21.15,6.25L17,6.25a1,1 0,0 0,-1 1v9.5a1,1 0,0 0,1 1h4.19L21.19,19a1,1 0,0 0,1 1L31,20a1,1 0,0 0,1 -1L32,15a1,1 0,0 0,-1 -1L22.15,14a1,1 0,0 0,-1 1v1.25L17.48,16.25L17.48,7.75h3.69L21.17,9a1,1 0,0 0,1 1L31,10A1,1 0,0 0,32 9ZM22.65,5.5h7.87v3L22.65,8.5ZM22.65,15.5h7.87v3L22.65,18.5Z"
android:fillColor="#3f3f3f"/>
</vector>

@ -28,7 +28,7 @@
<item
android:id="@+id/menu_group_manage"
android:icon="@drawable/ic_groups"
android:icon="@drawable/ic_groups_menu"
android:title="@string/group_manage"
app:showAsAction="never" />

Loading…
Cancel
Save