| | |
| | | import android.support.v4.app.Fragment |
| | | import android.support.v4.app.FragmentManager |
| | | import android.support.v4.app.FragmentTransaction |
| | | import android.support.v4.content.ContextCompat |
| | | import android.support.v7.app.AppCompatActivity |
| | | import android.support.v7.widget.Toolbar |
| | | import android.view.MenuItem |
| | | import android.view.ViewGroup |
| | | import android.view.inputmethod.InputMethodManager |
| | | import android.widget.EditText |
| | | import com.bumptech.glide.Glide |
| | | import io.reactivex.disposables.Disposable |
| | | import org.greenrobot.eventbus.EventBus |
| | |
| | | } catch (e: Exception) { |
| | | e.printStackTrace() |
| | | } |
| | | setContentView(getLayoutId()) |
| | | rootView = findViewById<ViewGroup>(android.R.id.content).getChildAt(0) as ViewGroup |
| | | getLayoutId()?.let { |
| | | setContentView(it) |
| | | rootView = findViewById<ViewGroup>(android.R.id.content).getChildAt(0) as ViewGroup |
| | | } |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | |
| | | } |
| | | |
| | | |
| | | abstract fun getLayoutId(): Int |
| | | abstract fun getLayoutId(): Int? |
| | | |
| | | /** |
| | | * 拓展activity中自动显示软键盘的方法 |
| | | */ |
| | | fun autoShowKeyboard(editText: EditText, delay: Long = 500) { |
| | | editText.postDelayed({ |
| | | ContextCompat.getSystemService(this, InputMethodManager::class.java)?.run { |
| | | editText.requestFocus() |
| | | showSoftInput(editText, 0) |
| | | } |
| | | }, delay) |
| | | } |
| | | |
| | | /** |
| | | * 拓展activity中隐藏软键盘的方法 |
| | | */ |
| | | fun hideKeyboard() { |
| | | this.window?.peekDecorView()?.let { |
| | | val inputManager = |
| | | this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
| | | inputManager.hideSoftInputFromWindow(it.windowToken, 0) |
| | | } |
| | | } |
| | | } |
| | | |
| | | fun Context.startActivity(cls: Class<*>) { |
| | |
| | | |
| | | inline fun FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) { |
| | | beginTransaction().func().commit() |
| | | } |
| | | |
| | | /** |
| | | * 拓展fragment中隐藏软键盘的方法 |
| | | */ |
| | | fun Activity.hideKeyboard() { |
| | | this.window?.peekDecorView()?.let { |
| | | val inputManager = |
| | | this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
| | | inputManager.hideSoftInputFromWindow(it.windowToken, 0) |
| | | } |
| | | } |