15

I am writing an app for android phones and after my splash screen it shows an activity which has several spinners and edittext views.

On an android device without a keyboard it shows the virtual keyboard which then blocks the rest of the app and looks unprofessional to me. I have tried to hide the virtual keyboard in the activity.onCreate method however no avail there.

My next option I tried was setting an onFocus listener to the actual offending edittext view and still no avail.

How can I prevent the virtual keyboard from showing until a user explicitly clicks an edittext view? Is there a way to give one of the spinner's focus since one of the spinners is before the edittext view in the layout xml?

jeep
  • 151
  • 1
  • 1
  • 3

3 Answers3

34

You can try setting the android:windowSoftInputMode attribute of your Activity's entry in the AndroidManifest.xml file. I think setting it to stateHidden might do what you want.

Here's the docs from the Android site.

mportuesisf
  • 5,587
  • 2
  • 33
  • 26
8

You can try this:

Oncreate of your activity, set the input type to TYPE_NULL. Then, onTouch, set it to TYPE_CLASS_TEXT.

    myText.setInputType(InputType.TYPE_NULL);

    myText.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
        myText.setInputType(InputType.TYPE_CLASS_TEXT);
        myText.onTouchEvent(event); // call native handler
        return true; // consume touch even
        } 
    });
Chris
  • 3,787
  • 13
  • 42
  • 49
  • Thanks a bunch, now my app acts more professional. I noticed other apps like the yahoo email app work in the same way, nice to have apps look alike to add to feel and functionality. – jeep Aug 02 '10 at 01:40
  • I believe this is a nice workaround, but that mportuesisf answer is a better one. – Richard Le Mesurier Nov 04 '11 at 13:21
0

There are several more answers with another experience on this issue in thread Automatic popping up keyboard on start Activity

Community
  • 1
  • 1
Sergei Pikalev
  • 516
  • 4
  • 5