반응형
안녕하세요 찌빠냥입니다.
EditText를 클릭하면 하단 키보드 팝업이 올라오는데요 여기에 일반 엔터키에 해당하는 부분이 상황에 따라 검색, 엔터, 기타 등등 변경됩니다. 기능을 어떻게 적용하는지 알아보겠습니다.
1. 안드로이드 레이아웃 xml 파일에서 변경
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:id="@+id/searchText"
/>
2. java에서 변경
EditText searchText = (EditText)findViewById(R.id.searchText);
searchBtn.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
3. 해당 키를 눌렀을 때 동작 구현
EditText searchText = (EditText)findViewById(R.id.searchText);
searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
switch(actionId){
case EditorInfo.IME_ACTION_SEARCH:
// 검색동작 구현
break;
case EditorInfo.IME_ACTION_GO:
// '이동' 에 대한 내용 구현
break;
default:
// 기본 동작 구현
break;
}
return true;
}
});
그 외 imeOptions 옵션 값에 대해서는 따로 검색해 주시면 되겠습니다.
감사합니다.
반응형
'개발' 카테고리의 다른 글
[안드로이드] 웹뷰 콘솔로그 찍기 (0) | 2020.06.15 |
---|---|
windows 특정 포트 죽이기 (0) | 2020.06.11 |
[Android]인텐트로 객체전달 (0) | 2020.05.08 |
[MSSQL] 문자열 교체하기 REPLACE (0) | 2020.05.06 |
[MSSQL] STUFF(문자열 치환)사용법 (0) | 2020.05.05 |
댓글