ProgramingTip

활동을 만들 때 EditText가 늘어나를 맞추지 않게 만드는 방법

bestdevel 2020. 11. 12. 19:26
반응형

활동을 만들 때 EditText가 늘어나를 맞추지 않게 만드는 방법


나는 제안 논의하는 다른 질문을 읽거나, 첫 번째 생성을 제외하고모두 내 레이아웃에서 작동합니다 .

현재이 onCreate방법 의 맨 위에 있습니다 .

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

^ 그것은 비록 시작시 키보드가 팝업되지 않지만 EditText여전히 집중되어 있습니다.

XMLEditText:

<EditText
    android:id="@+id/password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/changePass"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="167dp"
    android:ems="10"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textPassword"
    android:maxLength="30" >
</EditText>

내 활동이있을 때의 모습입니다.

여기에 이미지 설명 입력

문제는 일부 휴대 전화에서는 EditText이처럼 점점 늘어 납니다 . 집중하지 않기를 바랍니다 .

내가 한 일은 다음 레이아웃에 EditTexts늘어날수록 맞추지 않고 다음과 같이 보일 점에서 작동합니다.

여기에 이미지 설명 입력

그래도 동일한 레이아웃입니다. 이 화면은 사용자 가이 화면으로 돌아온 후의 화면입니다 . 화면이 XML은 동일하기 때문에 아무런 문제가 없음을 나타내지 XML만 문제는 EditText활동이 생성 될 때에 만 초점이 맞춰진다는을 구석으로입니다.

나는 조사를 다른 모든 질문은 이것에 도움이되지 않습니다. (하지만 그렇다고 키보드가 도움이되지 않습니까?) 처음 시작할 EditText때 첫 번째 스크린 샷이 아닌 두 번째 스크린 샷처럼 보이 도록 권장해야해야 합니까?


당신은 같은 레이아웃의 속성을 접근 할 수 있습니다 android:descendantFocusability="beforeDescendants".android:focusableInTouchMode="true"

예 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/mainLayout"
  android:descendantFocusability="beforeDescendants"
  android:focusableInTouchMode="true" >

    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/changePass"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="167dp"
        android:ems="10"
        android:imeOptions="flagNoExtractUi"
        android:inputType="textPassword"
        android:maxLength="30" >
    </EditText>

</RelativeLayout>

이것이 도움이 되길 바랍니다;)


XML 코드 :

<EditText
    android:id="@+id/password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/changePass"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="167dp"
    android:ems="10"
    android:focusable="false"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textPassword"
    android:maxLength="30" >
</EditText>

자바 코드 :

EditText edPwd = (EditText)findViewById(R.id.password);
edtPwd.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            v.setFocusable(true);
            v.setFocusableInTouchMode(true);
            return false;
        }
    });

xml에서 focusable false를 설정하고 코드를 통해 true로 설정하십시오.


main_layout에서 다음 두 줄을 추가하십시오.

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

예 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> *YOUR LAYOUT CODE* </RelativeLayout>

onCreate ()에 추가하십시오.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

또는 onCreateView ()

 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

XML 코드

<EditText 
    android:imeOptions="flagNoExtractUi"
    android:focusable="false"
    />

onClickListerner의 Java 코드

 mEdtEnterPhoneNumber.setFocusable(true);
    mEdtEnterPhoneNumber.setFocusableInTouchMode(true);

최고의 솔루션은 여기입니다 : https://stackoverflow.com/a/45139132/3172843

정확하고 간단한 솔루션을 위해서 setFocusable 허위이다 setFocusableInTouchMode 사실 . 따라서 EditText는 사용자가 EditText를 터치 할 때만 포커스를 얻습니다.

android:focusable="false"
android:focusableInTouchMode="true"

프로그래밍 방식으로이 작업을 수행 할 수 있습니다. 사용 editText.setEnabled(false)당신의 onStart()활동의 방법 (하지에서 onCreate ()에서 -이 어떤 방법은 GUI 구성 요소를 초기화하기 때문에)


android:focusable="false"비활성화하는 데 사용할 수 있지만 어떤 이유로 작동하지 않는 경우 a를 입력하면 LinearLayout레이아웃을 방해하지 않고 초점을 맞출 수 있습니다.

참고 : Eclipse는 LinearLayout내용이 없기 때문에 쓸모 없다는 오류를 표시합니다 . 아무 문제없이 무시할 수 있어야합니다.

예를 들면 :

<LinearLayout
    android:focusable="true"
    android:focusableInTouchMode="false"
    android:layout_width="0dp"
    android:layout_height="0dp"
    />
<EditText
    android:id="@+id/password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/changePass"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="167dp"
    android:ems="10"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textPassword"
    android:maxLength="30" >
</EditText>
</LinearLayout>

가장 쉬운 방법은

android:windowSoftInputMode="stateAlwaysHidden|adjustPan" 

Manifest.xml 파일의 활동 태그


1) 가장 간단한 방법은 매니페스트를 열고 액티비티 태그 사이에 다음 코드를 삽입합니다.

android:windowSoftInputMode="stateHidden"

2)이 속성을 상위 레이아웃에 넣습니다.

android:focusable="true" 
android:focusableInTouchMode="true"

Manifest에서 코드 아래에 복사하여 붙여 넣습니다.

 <activity
   android:name=".LoginActivity"
   android:windowSoftInputMode="stateAlwaysHidden"/>

<activity
            android:name=".MainActivity"
            android:windowSoftInputMode="stateAlwaysHidden" />

android : windowSoftInputMode = "stateAlwaysHidden"

Manifest.xml 파일의 활동 태그에이 줄을 추가합니다. EditText를 클릭하면 키보드에 초점이 맞춰집니다.


사용 android:focusable="false"안 함을 집중하기위한

<EditText
    android:id="@+id/password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/changePass"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="167dp"
    android:ems="10"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textPassword"
    android:maxLength="30"
 android:focusable="false" >

</EditText>

참고 URL : https://stackoverflow.com/questions/18295802/how-to-make-edittext-not-focused-when-creating-activity

반응형