티스토리 뷰
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<EditText
android:id="@+id/etContents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="James Kim"
android:textSize="26dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnShowKeyboard"
android:layout_width="220dp"
android:layout_height="65dp"
android:textAllCaps="false"
android:text="Show Keyboard"
android:textSize="20dp"
android:textStyle="italic"
android:layout_marginTop="30dp" />
<Button
android:id="@+id/btnCloseKeyboard"
android:layout_width="220dp"
android:layout_height="65dp"
android:textAllCaps="false"
android:text="Close Keyboard"
android:textSize="20dp"
android:textStyle="italic"
android:layout_marginBottom="300dp"/>
</LinearLayout>
MainActivity.kt
package com.jwsoft.kotlinproject
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.inputmethod.InputMethodManager
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
private lateinit var inputMethodManager: InputMethodManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
btnShowKeyboard.setOnClickListener {
etContents.requestFocus() // 포커스가 있어야 키보드가 노출됨.
inputMethodManager.showSoftInput(etContents, InputMethodManager.SHOW_IMPLICIT)
}
btnCloseKeyboard.setOnClickListener {
inputMethodManager.hideSoftInputFromWindow(
currentFocus?.windowToken,
InputMethodManager.HIDE_NOT_ALWAYS
)
}
}
}
'Android > Kotlin' 카테고리의 다른 글
[Kotlin] Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK (0) | 2020.09.02 |
---|---|
[Kotlin] lateinit vs Delegates.notNull<>() (0) | 2020.08.27 |
[Kotlin] STT (Speech-to-Text) (0) | 2020.08.24 |
[Kotlin] ArrayList.removeAt() (0) | 2020.08.20 |
[Kotlin] String.replace() (0) | 2020.08.20 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 안드로이드 #코틀린 #Android #Kotlin
- ViewModel
- ArrayList
- Kotlin
- CoordinatorLayout
- ViewPager2
- handler
- Intent
- View
- Vue.js #Vue.js + javascript
- TabLayout
- DataBinding
- coroutine
- James Kim
- MVVM
- java
- Android
- 자바
- JSONArray
- activity
- Design Pattern
- 코틀린
- fragment
- Livedata
- recyclerview
- Architecture Pattern
- JSONObject
- 혀가 길지 않은 개발자
- 안드로이드
- XML
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함