riku
2025-10-27 0f58aa8ea118c3bd0b28396febc58fdbd94eef75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cn.flightfeather.thirdappmodule.module.base
 
import android.graphics.drawable.Drawable
import android.support.v7.widget.Toolbar
import android.view.View
import android.widget.ImageView
import android.widget.TextView
 
/**
 * @author riku
 * Date: 2019/5/8
 * toolbar设置接口
 */
interface ToolbarSetInterface {
    fun initToolbar() {
        if (toolbarEnabled()) {
            //设置用户头像点击事件
            getHeadIcon().setOnClickListener {
                onHeadIconClick()
            }
            //左侧按钮
            getHeadIconRes()?.let {
                val icon = getHeadIcon()
                if (icon is ImageView) {
                    icon.setImageDrawable(it)
                }
            }
            //toolbar标题文字
            getMyTitleTextView()?.apply {
                getTitleText()?.let {
                    text = it
                    visibility = if (getTitleEnabled()) View.VISIBLE else View.INVISIBLE
                }
            }
            //右侧菜单按钮
            val menuList = getMenus() ?: emptyList()
            val visibilities = getMenuVisibility()
            val resources = getMenuRes()
            val listeners = getMenuClickListener()
            for (index in menuList.indices) {
                menuList[index].apply {
                    visibility = if (index < visibilities.size) visibilities[index]
                            ?: View.GONE else View.GONE
                    if (this is ImageView) {
                        setImageDrawable(if (index < resources.size) resources[index] else null)
                    }
                    setOnClickListener(if (index < listeners.size) listeners[index] else null)
                }
            }
        }
    }
    fun getToolBar(): Toolbar
 
    fun toolbarEnabled(): Boolean
 
    //toolbar左侧图标
    fun getHeadIcon(): View
    //toolbar左侧图标点击事件
    fun onHeadIconClick()
    //左侧按钮的图片资源
    fun getHeadIconRes(): Drawable? = null
 
    //toolbar居中标题
    fun getMyTitleTextView(): TextView?
    //是否展示标题栏中间标题
    fun getTitleEnabled(): Boolean
    //标题内容
    fun getTitleText(): String?
 
 
    //toolbar 右侧菜单
    fun getMenus():List<View>?
    //三个菜单按钮的可见性
    fun getMenuVisibility(): List<Int?>
    //三个菜单按钮的图片资源
    fun getMenuRes(): List<Drawable?>
    //三个菜单按钮的文本
    fun getMenuText(): List<String?> = emptyList()
    //三个菜单按钮的点击事件
    fun getMenuClickListener(): List<View.OnClickListener?>
}