package com.yidian.bcommon.extensions

import android.app.Activity
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.yidian.bcommon.R

fun Activity.hideKeyBoard(): Boolean {
  val mInputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
  return if (currentFocus != null) {
    mInputMethodManager.hideSoftInputFromWindow(currentFocus!!.windowToken, 0)
  } else {
    false
  }
}

fun AppCompatActivity.initTitleBar(toolbar: Toolbar, textView: TextView, title: String) {
  toolbar.title = ""
  setSupportActionBar(toolbar)
  supportActionBar?.let {
    it.setDisplayHomeAsUpEnabled(true)
    it.setDisplayShowHomeEnabled(true)
  }
  toolbar.setNavigationIcon(R.drawable.bcommon_icon_back)
  toolbar.setNavigationOnClickListener {
    onBackPressed()
  }
  // 设置title
  textView.text = title
}

