Android EditView '완료'버튼을 만들고 클릭 할 때 키보드를 숨기려면 어떻게해야합니까?
사용자가를 클릭하면 EditView
Android가 키보드를 열어 사용자가 EditView
.
문제는 사용자가 쓰기를 마치면 키보드를 숨길 방법이 없다는 것입니다. 사용자는 키보드를 숨기려면 뒤로 버튼을 눌러야합니다.
Done
키보드를 숨기는 버튼을 키보드에 표시하는 방법이 있습니까?
TextView.setImeOptions를 사용 하고 actionDone을 전달합니다. 처럼textView.setImeOptions(EditorInfo.IME_ACTION_DONE);
먼저 아래와 같이 대상 EditText와 android:imeOptions
동일한 속성 을 설정해야 actionDone
합니다. 그러면 EditText 소프트 키보드의 'RETURN'버튼이 'DONE'버튼으로 변경됩니다.
<EditText
android:id="@+id/edittext_done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter some text"
android:imeOptions="actionDone"
/>
및 다음을 모두 포함하십시오 .imeOptions
singleLine
<EditText
android:id="@+id/edittext_done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
/>
android:imeActionLabel="Done"
android:singleLine="true"
XML 파일에서 잘 작동합니다. 그러나 이것은 또한 editText
당신이 원하지 않을 수도있는 한 줄에 계속 입력하게 할 것입니다. 따라서 코드에 다음을 추가하면 모든 것을 한 줄에 입력하지 않아도됩니다.
mainText.setHorizontallyScrolling(false);
mainText.setMaxLines("Maximum integer value that you want to provide");
이것을 사용하십시오 :
android:singleLine="true"
완료 버튼
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
과
android:inputType="text"
XML에서
키보드에서 클릭 완료 처리
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event){
if(actionId == EditorInfo.IME_ACTION_DONE){
// Your action on done
return true;
}
return false;
}
});
`
이 두 줄을 사용하여 EditText
android:imeActionLabel="Done"
android:singleLine="true"
또는이 줄에 의해 프로그래밍 방식으로 달성 할 수 있습니다.
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
위젯에 대한 속성이 변경되지 않으면 android:imeOptions="actionDone"
레이아웃 xml
파일 에서 와 같이 사용하는 것이 더 나을 수 있습니다 .
사용하다:
android:imeActionLabel="Done"
android:singleLine="true"
ActionDone은 키보드가 숨겨 졌을 때 키보드에서 다음 버튼을 클릭 할 때 사용합니다. 텍스트 편집 또는 AppcompatEdit에서 사용합니다.
XML
1.1 AppCompatEdittext를 사용하는 경우
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"/>
1.2 Edittext를 사용하는 경우
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"/>
자바
EditText edittext= (EditText) findViewById(R.id.edittext);
edittext.setImeOptions(EditorInfo.IME_ACTION_DONE);
많은 사람들이 문제를 알지 못하는 사이에 어려움을 겪을 수 있다는 점을 지적해야합니다.
If you want the kb to hide when clicking Done
, and you set android:imeOptions="actionDone"
& android:maxLines="1"
without setting your EditText inputType
it will NOT work as the default inputType
for the EditText is not "text"
as a lot of people think.
so, setting only inputType
will give you the results you desire whatever what you are setting it to like "text"
, "number"
, ...etc.
For the code:
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
Actually you can set custom text to that little blue button. In the xml file just use
android:imeActionLabel="whatever"
on your EditText.
Or in the java file use
etEditText.setImeActionLabel("whatever", EditorInfo.IME_ACTION_DONE);
I arbitrarily choose IME_ACTION_DONE as an example of what should go in the second parameter for this function. A full list of these actions can be found here.
It should be noted that this will not cause text to appear on all keyboards on all devices. Some keyboards do not support text on that button (e.g. swiftkey). And some devices don't support it either. A good rule is, if you see text already on the button, this will change it to whatever you'd want.
'program story' 카테고리의 다른 글
오버플로 CSS 속성이 숨겨진 값으로 작동하도록 만드는 방법 (0) | 2020.08.10 |
---|---|
PascalCase를 pascal_case로 변환하는 방법? (0) | 2020.08.10 |
현재 날짜에서 7 일 빼기 (0) | 2020.08.10 |
vi 다시 그리기 화면을 만드는 방법은 무엇입니까? (0) | 2020.08.10 |
Swift에서 UIColorFromRGB를 어떻게 사용할 수 있습니까? (0) | 2020.08.10 |