티스토리 뷰
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private Button btnShowKeyboard;
private Button btnCloseKeyboard;
private EditText etContents;
private InputMethodManager inputMethodManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnShowKeyboard = findViewById(R.id.btnShowKeyboard);
btnCloseKeyboard = findViewById(R.id.btnCloseKeyboard);
etContents = findViewById(R.id.etContents);
inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
btnShowKeyboard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etContents.requestFocus(); // 포커스가 있어야 키보드가 노출됨.
inputMethodManager.showSoftInput(etContents, InputMethodManager.SHOW_IMPLICIT);
}
});
btnCloseKeyboard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
inputMethodManager.hideSoftInputFromWindow(
getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS
);
}
});
}
}
'Android > Java' 카테고리의 다른 글
[Java] Tic-tac-toe 게임으로 보는 MVC 패턴 (0) | 2020.09.17 |
---|---|
[Java] Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK (0) | 2020.09.02 |
[Java] STT (Speech-to-Text) (0) | 2020.08.24 |
[Java] ArrayList.remove() (0) | 2020.08.20 |
[Java] String.replace() (0) | 2020.08.20 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- activity
- handler
- coroutine
- 안드로이드 #코틀린 #Android #Kotlin
- 코틀린
- CoordinatorLayout
- ArrayList
- Android
- Livedata
- JSONArray
- 혀가 길지 않은 개발자
- Kotlin
- ViewModel
- View
- ViewPager2
- 안드로이드
- MVVM
- Vue.js #Vue.js + javascript
- James Kim
- TabLayout
- Architecture Pattern
- JSONObject
- java
- XML
- fragment
- Intent
- DataBinding
- 자바
- recyclerview
- Design Pattern
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함