How to disable keypad popup when on edittext?

2019-01-03 23:55发布

In my app the first view of all my screens is an EditText, so every time i go to a screen the onscreen keypad pops up. how can i disable this popingup and enable it when manually clicked on the 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 code:

<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>

the third view (EditText) is where the focus is.

28条回答
时光不老,我们不散
2楼-- · 2019-01-04 00:51
     edittext.setShowSoftInputOnFocus(false);

Now you can use any custom keyboard you like.

查看更多
做个烂人
3楼-- · 2019-01-04 00:51

try it.......i solve this problem using code:-

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);
}

nothing u can input by default calculator on anything but u can set any string.

try it

查看更多
SAY GOODBYE
4楼-- · 2019-01-04 00:51

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

查看更多
放我归山
5楼-- · 2019-01-04 00:53

Declare the global variable for InputMethodManager:

 private InputMethodManager im ;

Under onCreate() define it:

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

Set the onClickListener to that edit text inside oncreate():

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

This will work.

查看更多
地球回转人心会变
6楼-- · 2019-01-04 00:54

If you are using Xamarin you can add this

Activity[(WindowSoftInputMode = SoftInput.StateAlwaysHidden)]

thereafter you can add this line in OnCreate() method

youredittext.ShowSoftInputOnFocus = false;

If the targeted device does not support the above code, you can use the code below in EditText click event

InputMethodManager Imm = (InputMethodManager)this.GetSystemService(Context.InputMethodService);
Imm.HideSoftInputFromWindow(youredittext.WindowToken, HideSoftInputFlags.None);
查看更多
一纸荒年 Trace。
7楼-- · 2019-01-04 00:55

Add below code on your activity class.

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

Keyboard will pop-upped when user clicks on the EditText

查看更多
登录 后发表回答