[챕터 2-7-5] 키패드

2020. 2. 18. 22:28Android/Android 챕터 2-7

반응형

결과화면

입력상자에 터치하면 숫자 키패드 표시

 

키패드 닫기 클릭 시 키패드 비표시

 


프로젝트명 : MyKeypad

 

inputType : number

 

 


AndroidManifest.xml

 

더보기
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.minokuma.mykeypad">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 


MainActivity.java

 

더보기
package org.minokuma.mykeypad;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.hardware.input.InputManager;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
            }
        });
    }
}

 


 

 

반응형

'Android > Android 챕터 2-7' 카테고리의 다른 글

[챕터 2-7-4] 시크바  (0) 2020.02.18
[챕터 2-7-3] 웹 뷰  (0) 2020.02.18
[챕터 2-7-2] 애니메이션 슬라이딩  (0) 2020.02.18
[챕터 2-7-1] 애니메이션  (0) 2020.02.18