|
|
@ -4,6 +4,7 @@ import android.os.Bundle |
|
|
|
import android.view.Menu |
|
|
|
import android.view.Menu |
|
|
|
import android.view.MenuItem |
|
|
|
import android.view.MenuItem |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
|
|
|
|
import androidx.appcompat.view.menu.MenuBuilder |
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
import androidx.lifecycle.ViewModel |
|
|
@ -30,17 +31,29 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean { |
|
|
|
* 设置MENU图标颜色 |
|
|
|
return menu?.let { |
|
|
|
*/ |
|
|
|
if (it is MenuBuilder) { |
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean { |
|
|
|
it.setOptionalIconsVisible(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val bool = onCompatCreateOptionsMenu(it) |
|
|
|
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) |
|
|
|
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) |
|
|
|
val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default) |
|
|
|
val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default) |
|
|
|
for (i in 0 until menu.size()) { |
|
|
|
for (i in 0 until menu.size()) { |
|
|
|
(menu.getItem(i) as MenuItemImpl).let {//overflow:展开的item |
|
|
|
(menu.getItem(i) as MenuItemImpl).let { item -> |
|
|
|
DrawableUtils.setTint(it.icon, if (it.requiresOverflow()) defaultTextColor else primaryTextColor) |
|
|
|
//overflow:展开的item |
|
|
|
|
|
|
|
DrawableUtils.setTint( |
|
|
|
|
|
|
|
item.icon, |
|
|
|
|
|
|
|
if (item.requiresOverflow()) defaultTextColor else primaryTextColor |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bool |
|
|
|
|
|
|
|
} ?: super.onCreateOptionsMenu(menu) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open fun onCompatCreateOptionsMenu(menu: Menu): Boolean { |
|
|
|
return super.onCreateOptionsMenu(menu) |
|
|
|
return super.onCreateOptionsMenu(menu) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -74,7 +87,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
// return super.onMenuOpened(featureId, menu) |
|
|
|
// return super.onMenuOpened(featureId, menu) |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
|
|
|
final override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
|
|
|
item?.let { |
|
|
|
item?.let { |
|
|
|
if (it.itemId == android.R.id.home) { |
|
|
|
if (it.itemId == android.R.id.home) { |
|
|
|
supportFinishAfterTransition() |
|
|
|
supportFinishAfterTransition() |
|
|
@ -85,7 +98,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
open fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
return true |
|
|
|
return super.onOptionsItemSelected(item) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected fun initTheme() { |
|
|
|
protected fun initTheme() { |
|
|
|