your programing

EditText에서 키패드 팝업을 비활성화하는 방법은 무엇입니까?

lovepro 2020. 9. 25. 23:23
반응형

EditText에서 키패드 팝업을 비활성화하는 방법은 무엇입니까?


내 앱에서 모든 화면의 첫 번째보기는 EditText이므로 화면으로 이동할 때마다 화면 키패드가 나타납니다. 이 팝업을 비활성화하고 EditText를 수동으로 클릭했을 때 활성화하려면 어떻게해야합니까 ????

    eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed);

    eT.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {

            if(hasFocus){
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
            imm.hideSoftInputFromWindow(eT.getWindowToken(), 0);
            }
        }
    });

xml 코드 :

<ImageView
    android:id="@+id/feedPageLogo"
    android:layout_width="45dp"
    android:layout_height="45dp"
    android:src="@drawable/wic_logo_small" />

<Button
    android:id="@+id/goButton_feed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="@string/go" />

<EditText
    android:id="@+id/searchAutoCompleteTextView_feed"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/goButton_feed"
    android:layout_toRightOf="@id/feedPageLogo"
    android:hint="@string/search" />

<TextView
    android:id="@+id/feedLabel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/feedPageLogo"
    android:gravity="center_vertical|center_horizontal"
    android:text="@string/feed"
    android:textColor="@color/white" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ButtonsLayout_feed"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <Button
        android:id="@+id/feedButton_feed"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_margin="0dp"
        android:layout_weight="1"
        android:background="@color/white"
        android:text="@string/feed"
        android:textColor="@color/black" />

    <Button
        android:id="@+id/iWantButton_feed"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_margin="0dp"
        android:layout_weight="1"
        android:background="@color/white"
        android:text="@string/iwant"
        android:textColor="@color/black" />

    <Button
        android:id="@+id/shareButton_feed"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_margin="0dp"
        android:layout_weight="1"
        android:background="@color/white"
        android:text="@string/share"
        android:textColor="@color/black" />

    <Button
        android:id="@+id/profileButton_feed"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_margin="0dp"
        android:layout_weight="1"
        android:background="@color/white"
        android:text="@string/profile"
        android:textColor="@color/black" />
</LinearLayout>

<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/feedListView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/ButtonsLayout_feed"
    android:layout_below="@id/feedLabel"
    android:textSize="15dp" >
</ListView>

세 번째 뷰 (EditText)는 포커스가있는 곳입니다.


프로젝트 매니페스트 파일의 최적의 솔루션 거짓말 (의 AndroidManifest.xml은) 는에 다음과 같은 속성을 추가 activity구조

android : windowSoftInputMode = "stateHidden"


예:

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

기술:

  • 활동이 사용자주의의 초점이되는 경우 소프트 키보드의 상태 (숨겨 지거나 표시됨)입니다.
  • 활동의 기본 창에 대한 조정-소프트 키보드를위한 공간을 만들기 위해 크기를 더 작게 조정했는지 또는 창 일부가 소프트 키보드로 덮일 때 현재 포커스가 보이도록 내용이 이동되는지 여부.

도입 :

  • API 레벨 3.

문서에 연결

참고 : 여기에 설정된 값 ( "stateUnspecified"및 "adjustUnspecified"제외)은 테마에 설정된 값보다 우선합니다.


EditText 위에 '가짜'초점을 맞춘보기를 만들어야합니다.

다음과 같은 것 :

<!-- Stop auto focussing the EditText -->
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="@android:color/transparent"
    android:focusable="true"
    android:focusableInTouchMode="true">
</LinearLayout>

<EditText
    android:id="@+id/searchAutoCompleteTextView_feed"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:inputType="text" />

이 경우에는 LinearLayout을 사용하여 포커스를 요청했습니다. 도움이 되었기를 바랍니다.

이것은 완벽하게 작동했습니다 ... Zaggo0 덕분에


     edittext.setShowSoftInputOnFocus(false);

이제 원하는 사용자 정의 키보드를 사용할 수 있습니다.


사람들은 여기에 많은 훌륭한 솔루션을 제안했지만 EditText와 함께이 간단한 기술을 사용했습니다 (Java 및 AnroidManifest.xml에는 아무것도 필요하지 않음). Focusable 및 focusableInTouchMode를 EditText에서 직접 false로 설정하십시오.

 <EditText
        android:id="@+id/text_pin"
        android:layout_width="136dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:textAlignment="center"
        android:inputType="numberPassword"
        android:password="true"
        android:textSize="24dp"
        android:focusable="false"
        android:focusableInTouchMode="false"/>

여기서 내 의도는 사용자에게 PIN을 입력하도록 요청하고 사용자 지정 PIN 패드를 표시하려는 앱 잠금 활동에서이 편집 상자를 사용하는 것입니다. Android Studio 2.1에서 minSdk = 8 및 maxSdk = 23으로 테스트되었습니다.

여기에 이미지 설명 입력


활동 클래스에 아래 코드를 추가하십시오.

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

사용자가 EditText를 클릭하면 키보드가 팝업됩니다.


다음 코드를 사용하여 화상 키보드를 비활성화 할 수 있습니다.

InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(editText.getWindowToken(), 0);

두 가지 간단한 솔루션 :

첫 번째 솔루션 은 매니페스트 xml 파일의 코드 줄 아래에 추가됩니다. Manifest 파일 (AndroidManifest.xml)에서 활동 구성에 다음 속성을 추가하십시오.

android : windowSoftInputMode = "stateHidden"

예:

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

두 번째 솔루션 은 활동에서 코드 줄 아래에 추가하는 것입니다.

//Block auto opening keyboard  
  this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

위의 솔루션 중 하나를 사용할 수 있습니다. 감사


InputMethodManager에 대한 전역 변수를 선언합니다.

 private InputMethodManager im ;

onCreate () 아래에서 정의하십시오.

 im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
 im.hideSoftInputFromWindow(youredittext.getWindowToken(), 0);

oncreate () 내부의 편집 텍스트로 onClickListener를 설정합니다.

 youredittext.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        im.showSoftInput(youredittext, InputMethodManager.SHOW_IMPLICIT);
    }
});

작동합니다.


다음 코드를 사용하여 아래에 작성하십시오. onCreate()

InputMethodManager inputManager = (InputMethodManager)
                                   getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                                   InputMethodManager.HIDE_NOT_ALWAYS);         
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

시도해보십시오 ....... 코드를 사용하여이 문제를 해결합니다.

EditText inputArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
inputArea = (EditText) findViewById(R.id.inputArea);

//This line is you answer.Its unable your click ability in this Edit Text
//just write
inputArea.setInputType(0);
}

기본 계산기로 아무것도 입력 할 수 없지만 어떤 문자열도 설정할 수 있습니다.

시도 해봐


이것을 시도하십시오 :

EditText yourEditText= (EditText) findViewById(R.id.yourEditText); 
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); 

닫으려면 다음을 사용할 수 있습니다.

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
 imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0); 

코드에서 다음과 같이 시도하십시오.

ed = (EditText)findViewById(R.id.editText1);

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
imm.hideSoftInputFromWindow(ed.getWindowToken(), 0);  

ed.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
        imm.showSoftInput(ed, InputMethodManager.SHOW_IMPLICIT);  
    }
});

글쎄, 나는 같은 문제가 있었고 XML 파일에서 초점을 맞출 수 있었다.

<EditText
            android:cursorVisible="false"
            android:id="@+id/edit"
            android:focusable="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

아마도 보안을 찾고있을 것입니다. 이것은 또한 도움이 될 것입니다.


좋은 솔루션에 대해 @AB에게 감사드립니다.

    android:focusableInTouchMode="false"

이 경우 편집 텍스트에서 키보드를 비활성화하려면 edittext 태그 라인 android : focusableInTouchMode = "false"추가하십시오 .

Android Studio 3.0.1 minsdk 16, maxsdk26에서 나를 위해 일하십시오.


onCreate()방법에 다음 코드를 사용하십시오.

    editText = (EditText) findViewById(R.id.editText);
    editText.requestFocus();
    editText.postDelayed(new Runnable() {
        public void run() {
            InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.hideSoftInputFromWindow(
                    editText.getWindowToken(), 0);
        }
    }, 200);

해야 할 일은 android:focusableInTouchMode="false"xml의 ​​EditText에 추가 하는 것뿐입니다 . (누군가가 여전히 쉬운 방법으로 수행하는 방법을 알아야하는 경우)


Xamarin 사용자의 경우 :

[Activity(MainLauncher = true, 
        ScreenOrientation = ScreenOrientation.Portrait, 
        WindowSoftInputMode = SoftInput.StateHidden)] //SoftInput.StateHidden - disables keyboard autopop

       <TextView android:layout_width="match_parent"
                 android:layout_height="wrap_content"

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

                <requestFocus/>
      </TextView>

      <EditText android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

Xamarin을 사용하는 경우 이것을 추가 할 수 있습니다.

Activity[(WindowSoftInputMode = SoftInput.StateAlwaysHidden)]

그런 다음 OnCreate () 메서드에이 줄을 추가 할 수 있습니다.

youredittext.ShowSoftInputOnFocus = false;

대상 장치가 위 코드를 지원하지 않는 경우 EditText 클릭 이벤트에서 아래 코드를 사용할 수 있습니다.

InputMethodManager Imm = (InputMethodManager)this.GetSystemService(Context.InputMethodService);
Imm.HideSoftInputFromWindow(youredittext.WindowToken, HideSoftInputFlags.None);

입력을 받기 위해 대화 상자를 표시하려는 코드에서 다음 패턴이 잘 작동 함을 발견했습니다 (예 : 텍스트 필드에 표시된 문자열은 대화 상자의 확인란 목록에서 선택한 결과입니다. 키보드를 통해 입력 한 텍스트).

  1. Disable soft input focus on the edit field. I can't disable for the entire activity, as there are edit fields I do want the keyboard to be used for in the same layout.
  2. Initial clicks in the text field yield a focus change, a repeated click yields a click event. So I override both (here I don't refactor the code out to illustrate both handlers do the same thing):

    tx = (TextView) m_activity.findViewById(R.id.allergymeds);
    if (tx != null) {
        tx.setShowSoftInputOnFocus(false);
        tx.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                if (hasFocus) {
                    MedicationsListDialogFragment mld = new MedicationsListDialogFragment();
                    mld.setPatientId(m_sess.getActivePatientId());
                    mld.show(getFragmentManager(), "Allergy Medications Dialog");
                }
            }
        });
        tx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MedicationsListDialogFragment mld = new MedicationsListDialogFragment();
                mld.setPatientId(m_sess.getActivePatientId());
                mld.show(getFragmentManager(), "Allergy Medications Dialog");
            }
        });
    }
    

In a Android app I was building, I had three EditTexts in a LinearLayout arranged horizontally. I had to prevent the soft keyboard from appearing when the fragment loaded. In addition to setting focusable and focusableInTouchMode to true on the LinearLayout, I had to set descendantFocusability to blocksDescendants. In onCreate, I called requestFocus on the LinearLayout. This prevented the keyboard from appearing when the fragment is created.

Layout -

    <LinearLayout
       android:id="@+id/text_selector_container"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:weightSum="3"
       android:orientation="horizontal"
       android:focusable="true"
       android:focusableInTouchMode="true"
       android:descendantFocusability="blocksDescendants"
       android:background="@color/black">

       <!-- EditText widgets -->

    </LinearLayout>

In onCreate - mTextSelectorContainer.requestFocus();


If anyone is still looking for the easiest solution, set the following attribute to true on your parent layout

android:focusableInTouchMode="true"

Example:

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="true">

.......
......
</android.support.constraint.ConstraintLayout>

Use This to enable and disable EditText....

InputMethodManager imm;

imm = (InputMethodManager)
getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);

if (isETEnable == true) {

    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    ivWalllet.setImageResource(R.drawable.checkbox_yes);
    etWalletAmount.setEnabled(true);
    etWalletAmount.requestFocus();
    isETEnable = false;
    } 
else {

    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY,0);
    ivWalllet.setImageResource(R.drawable.checkbox_unchecked);
    etWalletAmount.setEnabled(false);
    isETEnable = true;
    }

Try this answer,

editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);

Note: only for API 11+


private InputMethodManager imm;

...


editText.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        v.onTouchEvent(event);
        hideDefaultKeyboard(v);
        return true;
    }
});

private void hideDefaultKeyboard(View et) {
  getMethodManager().hideSoftInputFromWindow(et.getWindowToken(), 0);
}

private InputMethodManager getMethodManager() {
        if (this.imm == null) {
            this.imm = (InputMethodManager)  getContext().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
        }
  return this.imm;
}

Simple,Just Remove "" tag from the xml file


for any textview at your activity (or create fake empty textfiew with android:layout_width="0dp" android:layout_height="0dp" ) and add for this textview next: android:textIsSelectable="true"


Just need to add property android:focusable="false" in particular EditText in the layout xml. Then you can write click listner for EditText without keypad popup.


It issue can be sorted by using, No need to set editText inputType to any values, just add the below line, editText.setTextIsSelectable(true);

참고 URL : https://stackoverflow.com/questions/10611833/how-to-disable-keypad-popup-when-on-edittext

반응형