에이치의 모바일 앱 개발
keypad setting version 1.0.1 본문
※토글소프트 인풋의 경우..
키보드를 무조건 사라지게 하는게 아니라 현재 상태의 반대로 만든다.(예로 무조건 사라지게 하고 싶을 때 사용하면 된다.)
----------------------------xml 코드---------------------------- <EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="text"
android:imeOptions="normal" /> <!--특별한 의미 없음-->
android:imeOptions="actionUnspecified" /> <!--특별한 의미 없음-->
android:imeOptions="actionNone" /> <!--특별한 의미 없음-->
android:imeOptions="actionGo" /> <!--'이동'의 의미 (예 : 웹 브라우져에서 사용)--><
android:imeOptions="actionSearch" /> <!--'검색'의 의미 (예 : 네이버 검색창)-->
android:imeOptions="actionSend" /> <!--'보내기'의 의미 (예 : 메세지 작성시 사용)-->
android:imeOptions="actionNext" /> <!--'다음'의 의미 (예 : 회원가입시 다음 필드로 이동시)-->
android:imeOptions="actionDone" /> <!--'완료'의 의미 (예 : 정보 입력창)-->
android:imeOptions="actionPrevious" /> <!--'이전'의 의미 (예 : 회원가입시 이전 필드로 이동시) - API11부터 가능-->
----------------------------자바 코드----------------------------
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EditText editText = new EditText(this);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NONE) {// 특별한 의미 없음
if (actionId == EditorInfo.IME_ACTION_UNSPECIFIED) {// 특별한 의미 없음
if (actionId == EditorInfo.IME_ACTION_GO) {// '이동'의 의미 (예 : 웹 브라우져에서 사용)
if (actionId == EditorInfo.IME_ACTION_SEARCH) {// '검색'의 의미 (예 : 네이버 검색창)
if (actionId == EditorInfo.IME_ACTION_SEND) {// '보내기'의 의미 (예 : 메세지 작성시 사용)
if (actionId == EditorInfo.IME_ACTION_NEXT) {// '다음'의 의미 (예 : 회원가입시 다음 필드로 이동시)
if (actionId == EditorInfo.IME_ACTION_DONE) {// '완료'의 의미 (예 : 정보 입력창)
if (actionId == EditorInfo.IME_ACTION_PREVIOUS) { // '이전'의 의미 (예 : 회원가입시 이전 필드로 이동시) - API11부터 가능
}}}}}}}
return true;
}
return false;
}
});
}
}
//한 클래스 내
setupUI(findViewById(R.id.activity_main));
}
public void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
public void setupUI(View view) {
//Set up touch listener for non-text box views to hide keyboard.
if(!(view instanceof EditText)) {
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideSoftKeyboard(MainActivity.this);
return false;
}
});
}
//If a layout container, iterate over children and seed recursion.
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
setupUI(innerView);
}
}
}
//다른 클래스 public class Keyboard {
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
public static void setupUI(View view, final Activity activity) {
//Set up touch listener for non-text box views to hide keyboard.
if(!(view instanceof EditText)) {
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideSoftKeyboard(activity);
return false;
}
});
}
//If a layout container, iterate over children and seed recursion.
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
setupUI(innerView, activity);
}
}
}
}
'Android > Android 개발 소스' 카테고리의 다른 글
CustomAdapter-ViewHolder (0) | 2017.12.23 |
---|---|
ListView Hegiht Setting version 1.0.1 (0) | 2017.12.23 |
TextView> UI Postion Setting version 1.0.1 (0) | 2017.12.23 |
내 위치 정보 가져오기<확장> (0) | 2017.12.23 |
내 위치 정보 가져오기<기본> (0) | 2017.12.23 |