텍스트 편집시 자동 초점 비활성화
편집 텍스트가 있습니다.
<LinearLayout android:id="@+id/linearLayout7" android:layout_width="match_parent" android:layout_height="wrap_content">
<EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:id="@+id/editText1" android:text="3">
<requestFocus></requestFocus>
</EditText>
<Button android:text="Button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button2"></Button>
</LinearLayout>
그리고 그 아래에 다른 것들
내가 가진 문제는 앱이 시작될 때 포커스가 입력에 있다는 것입니다. 앱이 시작될 때 포커스가 입력에 집중되는 것을 원하지 않습니다.
나는 제거를 시도했다
<requestFocus></requestFocus>
아무것도하지 않았습니다.
다음 android:focusable="true"
과 같이 EditTextandroid:focusableInTouchMode="true"
의 부모 레이아웃에 및 요소를 추가합니다 .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout7" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true" android:focusableInTouchMode="true">
도움이 될 것 같아요.
NO 더 많은 작업 ... Manifest.xml 파일의 활동 태그에 android : windowSoftInputMode = "stateAlwaysHidden"을 추가하기 만하면됩니다.
편집 텍스트의 기본 초점을 지우려면 다음 두 가지 속성을 사용하십시오.
android:focusable="false"
android:focusableInTouchMode="true"
부모 선형 레이아웃 내부.
예를 들면 :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="true"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="email id"
android:inputType="textEmailAddress"
android:maxLines="1"
/>
</LinearLayout>
활동 생성시 키보드를 숨기려면 매니페스트 파일 활동 태그 내에 다음 속성을 사용합니다. 예를 들면 다음과 같습니다.
<activity
android:configChanges="screenSize|orientation|keyboardHidden"
android:screenOrientation="portrait"
android:name=".activities.LoginActivity"
android:windowSoftInputMode="stateHidden|adjustResize"/>
버튼을 클릭하거나 일부 이벤트가 발생할 때 키보드를 숨기려면 다음 코드를 사용하십시오.
public void onClick(View v) {
try {
//InputMethodManager is used to hide the virtual keyboard from the user after finishing the user input
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isAcceptingText()) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
} catch (NullPointerException e) {
Log.e("Exception", e.getMessage() + ">>");
}
}
} catch (NullPointerException e) {
Log.e("Exception", e.getMessage() + ">>");
}
활동을 떠난 후 텍스트 필드 편집에서 초점을 벗어나고 싶은 경우
@Override
protected void onResume() {
super.onResume();
mEmail.clearFocus();
mPassword.clearFocus();
}
마지막으로 양식을 제출할 때 편집 텍스트 필드의 데이터를 지우려면
@Override
protected void onResume() {
super.onResume();
mEmail.getText().clear();
mPassword.getText().clear();
}
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px" />
<EditText android:text=""
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/hint">
</EditText>
다른 코딩이 필요하지 않으며 간단하고 명확한 솔루션입니다.
당신은 숨기기 키보드와 숨겨진 창 소프트 입력 모드 사용 android:focusable="false"
및android:focusableInTouchMode="true"
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
그것은 나를 위해 일했으며 소원도 당신을 도울 것입니다.
다음 중 하나 :
android:windowSoftInputMode="stateAlwaysHidden"
자동 초점을 비활성화하려는 특정 활동 아래의 Manifest.xml 파일에이 특성을 추가하십시오. 단점 : 소프트 키보드 만 숨기고 커서는 그대로 유지됩니다.
기타 :
android:focusableInTouchMode="true"
이 속성을 UI xml 파일 (부모 레이아웃 아래)에 추가하면 키보드도 모두 포커스를 숨길 수 있습니다.
<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="48dp"
android:focusable="false"
android:focusableInTouchMode="false" />
detailInputView = (EditText) debugToolsView.findViewById(R.id.input);
detailInputView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
detailInputView.setFocusable(true);
detailInputView.setFocusableInTouchMode(true);
return false;
}
});
Just add the following to your main layout view xml tag:
android:focusableInTouchMode="true"
Hei Lee,
There are several way to do this, Mudassir has give a way to you to do that.
If the idea doesn't work, then do just simple thing-
In your AndroidManifest>Activity
add this simple code:
android:windowSoftInputMode="stateHidden"
Nothing need to do in EditText in XML, all will be work and no focus will appear.
Look the real life example code:
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
try this code in LinearLayout
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:hint="Search..."
android:drawableRight="@drawable/ic_search"
android:id="@+id/search_tab_hotbird_F"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyHotbird_F"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
for clear default requestFocuse you should set your View's parent focusable="true" like this below
<android.support.constraint.ConstraintLayout
android:id="@+id/coordinatorChild"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
참고URL : https://stackoverflow.com/questions/7593887/disable-auto-focus-on-edit-text
'developer tip' 카테고리의 다른 글
C #을 사용하여 각 단어의 첫 문자 또는 전체 문자열의 첫 문자를 대문자로 바꾸는 방법은 무엇입니까? (0) | 2020.12.14 |
---|---|
Python, 기본 인증을 사용하는 HTTPS GET (0) | 2020.12.14 |
목록의 요소 합산 (0) | 2020.12.14 |
프로세스 ID를 캡처하고 존재하는 경우 종료하는 쉘 스크립트 (0) | 2020.12.14 |
함수를`constexpr`로 선언하지 ** 않는 ** 이유는 무엇입니까? (0) | 2020.12.13 |