user6787631
user6787631

Reputation:

how I can remove the keyboard that appears automatically onCreate?

I have an edit text with custom keyboard or numpad my problem is when I open my app the android keyboard appears automatically I don't want for that to happen my apps idea is simple when i click on edit text my custom keyboard appears . so how I can remove the android keyboard that appears at the first by the way if i cancel it manually in the app it never shows up but as i say on reopen the app appears again please help

enter image description here

enter image description here

public class BasicOnKeyboardActionListener implements OnKeyboardActionListener {

private Activity mTargetActivity;

/***
 * 
 * @param targetActivity
 *            Activity a cui deve essere girato l'evento
 *            "pressione di un tasto sulla tastiera"
 */
public BasicOnKeyboardActionListener(Activity targetActivity) {
    mTargetActivity = targetActivity;
}

@Override
public void swipeUp() {
    // TODO Auto-generated method stub

}

@Override
public void swipeRight() {
    // TODO Auto-generated method stub

}

@Override
public void swipeLeft() {
    // TODO Auto-generated method stub

}

@Override
public void swipeDown() {
    // TODO Auto-generated method stub

}

@Override
public void onText(CharSequence text) {
    // TODO Auto-generated method stub

}

@Override
public void onRelease(int primaryCode) {
    // TODO Auto-generated method stub

}

@Override
public void onPress(int primaryCode) {
    // TODO Auto-generated method stub

}

@Override
public void onKey(int primaryCode, int[] keyCodes) {
    long eventTime = System.currentTimeMillis();
    KeyEvent event = new KeyEvent(eventTime, eventTime,
            KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
            KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);

    mTargetActivity.dispatchKeyEvent(event);
}

CustomKeyboardView.class

public class CustomKeyboardView extends KeyboardView {

public CustomKeyboardView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void showWithAnimation(Animation animation) {
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            setVisibility(View.VISIBLE);
        }
    });

    setAnimation(animation);
}

KeyboardWidgetTutorialActivity.class

public class KeyboardWidgetTutorialActivity extends Activity {

private CustomKeyboardView mKeyboardView;
private View mTargetView;
private Keyboard mKeyboard;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    mKeyboard = new Keyboard(this, R.xml.keyboard);
    mTargetView = (EditText) findViewById(R.id.target);
    mTargetView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Dobbiamo intercettare l'evento onTouch in modo da aprire la
            // nostra tastiera e prevenire che venga aperta quella di
            // Android
            showKeyboardWithAnimation();
            return true;
        }
    });

    mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
    mKeyboardView.setKeyboard(mKeyboard);
    mKeyboardView
            .setOnKeyboardActionListener(new BasicOnKeyboardActionListener(
                    this));
}

/***
 * Mostra la tastiera a schermo con una animazione di slide dal basso
 */
private void showKeyboardWithAnimation() {
    if (mKeyboardView.getVisibility() == View.GONE) {
        Animation animation = AnimationUtils
                .loadAnimation(KeyboardWidgetTutorialActivity.this,
                        R.anim.slide_in_bottom);
        mKeyboardView.showWithAnimation(animation);
    }
}

this is the main xml

<RelativeLayout android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout android:layout_width="fill_parent"
    android:id="@+id/container" android:layout_alignParentTop="true"
    android:layout_height="fill_parent" android:layout_above="@+id/keyboard_view">
    <EditText android:layout_width="fill_parent" android:id="@+id/target"
        android:layout_height="wrap_content" />
</LinearLayout>

<it.anddev.tutorial.CustomKeyboardView
    android:id="@+id/keyboard_view" android:visibility="gone"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"></it.anddev.tutorial.CustomKeyboardView>

Upvotes: 0

Views: 139

Answers (9)

John Kalimeris
John Kalimeris

Reputation: 86

You can add

android:focusable="true" 
android:focusableInTouchMode="true"
android:descendantFocusability="blocksDescendants"

to LinearLayout to remove focus from EditText.

Upvotes: 0

kgandroid
kgandroid

Reputation: 5595

Create this method and just call it from onCreate():

private void hideSoftKeyBoard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

    if(imm.isAcceptingText()) { // verify if the soft keyboard is open                      
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

Upvotes: 0

Sarbjyot
Sarbjyot

Reputation: 136

you just define that code in the manifest file.

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

Hope this help you..

Upvotes: 0

Ram Suthakar
Ram Suthakar

Reputation: 275

Add a new class Utilities.java include the below code

public static void hideKeypad(Context context, View edit) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}

then call the below code in which class you want to hide the keyboard

Utilities.hideKeypad(thisActivity, txtName);

Example:

txtName --> you can pass your Edittext variable here

Upvotes: 1

pradip_android
pradip_android

Reputation: 303

Add below line of code in your Linear Layout

android:focusable="true">

Upvotes: 0

iamabhaykmr
iamabhaykmr

Reputation: 2011

You can hide the keyboard for your activity in Manifest file by adding line below to corresponding activity tag:

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

Upvotes: 0

Harneev
Harneev

Reputation: 554

I've used following code for this problem earlier:

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

use this on onCreate()

Upvotes: 0

Vaibhav Kadam
Vaibhav Kadam

Reputation: 699

This will help

            InputMethodManager inputMethodManager = (InputMethodManager)  this.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);

Upvotes: 0

Mahesh Giri
Mahesh Giri

Reputation: 1840

Just do this

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

Upvotes: 0

Related Questions