简体   繁体   中英

EditText Android Studio keyboard

I have a problem: I click in the EdditText but the keyboard doesn't appear. I don't know how can I do to resolve the problem:

    et_num.setText (et_num.getText());

        et_num.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                et_num= (EditText) findViewById(R.id.et_num);
                et_num.requestFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(et_num, InputMethodManager.SHOW_IMPLICIT);
                //InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

              return false;
            };

        });


This can be an issue of focus on your EditText. Just add <RequestFocus /> after the EditText in your app xml layout file.
Example:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/et_num"
    android:hint="0"
    android:inputType="number"
    android:focusableInTouchMode="true"
    android:focusable="true" />
    <requestFocus />

Also as @cyroxis said, If you're using a emulator with a keyboard you must configure the settings of the device to use the soft, in an Api 23 custom phone just tabbing twice at the screen will show you an icon, just touch and will appear the soft keyboard.

Also you can make a public method to hide the keyboard on lose focus.

public void hide_board()
{
    InputMethodManager im=(InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
    im.hideSoftInputFromWindow(b_calcula.getWindowToken(), 0);
}

Hope it helps.

to make your keyboard visible

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

or else you can set in manifest also

android:windowSoftInputMode="stateAlwaysVisible"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM