How to force soft keyboard to be visible?

Showing 1-19 of 19 messages
How to force soft keyboard to be visible? Mike Collins 9/17/09 1:17 PM
I have a dialog that requires the use to type something.  I'd like to
force the soft keyboard to be visible when this window starts.

I've tried most everything that looks applicable and nothing works.

The API demos of SDK 1.5 have a set of windows that have this
android:windowSoftInputMode="stateVisible|adjustPan" set in the
manifest and they don't get the soft keyboard either.

Using either the 1.5 emulator or the 1.6 emulator or a 1.5 phone.

tia,
  mike
Re: [android-developers] How to force soft keyboard to be visible? loctarar 9/18/09 2:16 AM
super.onCreate(savedInstanceState);

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
Re: How to force soft keyboard to be visible? Mike Collins 9/18/09 10:17 AM
That does work, thanks.

Of course now I can't get it to go down when the activity finishes.
Apparently
because there is no equivalent of HIDE_FORCED.  The only two HIDE's
options don't take down a FORCED show.  But without a FORCED show
it doesn't show up unless the user asks for it.

This seems like obvious UI, to me.  I have a dialog that requires
keyboard input.
I'd like to open the soft keyboard to save the user having to click
the single edit
box.  When the user is finished they click the OK button and I'd like
to take down
the soft keyboard that I put up before returning to where ever.

Given the APIs this doesn't seem possible.  Am I missing something
here?

tia,
  mike
Re: [android-developers] Re: How to force soft keyboard to be visible? Dianne Hackborn 9/18/09 12:23 PM
Typically the emulator runs as a device that has a keyboard, in which case the system deliberately does not automatically show the IME because the user has easy access to a real keyboard.  It is recommended to not defeat this behavior, resulting in an inconsistent behavior with the rest of the applications.--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Re: How to force soft keyboard to be visible? Mike Collins 9/18/09 4:13 PM
The behavior I'm talking about is on a locked G1 with 1.5, I did not
expect the
emulator to be very useful.

The behavior on a myTouch (locked, 1.5) is really bizarre.

I'm beginning to think that I'm going to pull all the soft keyboard
code out
and let the user do the extra work.

  mike

Re: [android-developers] Re: How to force soft keyboard to be visible? Dianne Hackborn 9/18/09 5:42 PM
The G1 has a keyboard, so it works as I said -- the IME is not shown by default.  This is a policy decision of the platform.

On a myTouch, since it doesn't have a keyboard, the IME will be shown by default in various cases (for example when you enter the edit contacts screen) when the app has indicated that is desired with the input options.
Re: How to force soft keyboard to be visible? James W 9/21/09 6:13 AM
I have exactly the same requirement.

Running on a Hero, which only has a soft keyboard. The above code is
copied exactly, yet it doesnt work. The keyboard is not shown no
matter where I put the code, before or after SetContentView().

This seems like a pretty standard thing to want to do, is there some
other way of doing this?

Thanks in advance..
James

On Sep 19, 8:42 am, Dianne Hackborn <hack...@android.com> wrote:
> The G1 has a keyboard, so it works as I said -- the IME is not shown by
> default.  This is a policy decision of the platform.
>
> On a myTouch, since it doesn't have a keyboard, the IME will be shown by
> default in various cases (for example when you enter the edit contacts
> screen) when the app has indicated that is desired with the input options.
>
> On Fri, Sep 18, 2009 at 4:13 PM, Mike Collins <mike.d.coll...@gmail.com>wrote:
>
>
>
>
>
>
>
> > The behavior I'm talking about is on a locked G1 with 1.5, I did not
> > expect the
> > emulator to be very useful.
>
> > The behavior on a myTouch (locked, 1.5) is really bizarre.
>
> > I'm beginning to think that I'm going to pull all the soft keyboard
> > code out
> > and let the user do the extra work.
>
> >  mike
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.- Hide quoted text -
>
> - Show quoted text -
Re: [android-developers] Re: How to force soft keyboard to be visible? Dianne Hackborn 9/21/09 10:15 AM
All I can say is the edit contacts activity in the standard platform does this just fine, using the standard API.  Either you are doing something different than it, or HTC's IME has some different behavior, but I don't know much about either of those.  Do note that normally the system will not show the IME by default if it has to use panning on the target window (instead of resize), and the only way to get around this would be to explicitly show the IME when you receive focus.hac...@android.com
Re: [android-developers] Re: How to force soft keyboard to be visible? Dianne Hackborn 9/21/09 10:16 AM
Oh also it doesn't show by default if the IME needs to run in fullscreen (typically because the device is in landscape).  Both of these are because showing the IME is these cases is much more disruptive than showing it when the target window can resize nicely to show all of its important UI in conjunction with the IME.
Re: How to force soft keyboard to be visible? Mike Collins 9/21/09 10:44 AM

I have removed all the code around putting up or taking down or
otherwise trying to
influence the soft keyboard.  This is running on a stock G1 with 1.5

I have two activities reachable from one main activity.  All three
activites have
a single AutoCompleteTextView.  All 3 edit boxes have InputType set,
the main
activity is set to "text" the two subactivity edit boxes are set to
"number".  The
manifest makes no keyboard statements.

If the soft keyboard is not visible in the main window transitions to
the sub windows
work as expected.

However, if the soft keyboard is visible in the main activity because
the user has
touched the AutoCompleteTextView transitioning to one of the sub
activities takes
the soft keyboard down, transitioning to the other sub activity leaves
it up.

Is this expected behavior?  Do I have any control over this?  If so
what?

tia,
  mike
Re: How to force soft keyboard to be visible? dwass 9/22/09 1:06 AM
Hi Dianne,

You say that the G1 has a keyboard and so the IME is not shown by
default. I don't understand that statement. Yes, the G1 has a
keyboard, but it isn't always OPEN. Especially if the device is in
portrait mode, the keyboard is probably NEVER open. The device should
be smart enough so that it opens the keyboard if there is no keyboard
open. Either that, or we need a way to show the keyboard when we want
to (and hide it again when we don't).

My current problem is this: When I start an activity, the first
EditText field in the layout is focused automatically, but the soft
keyboard is not automatically shown. The user must either click (with
trackball) or touch the field to open the soft keyboard. IMHO the
developer should be able to say that he wants the keyboard shown at
this point.

Any suggestions? I've tried all the "force show keyboard" suggestions
and they sometimes do work, but usually you get stuck with the
keyboard being shown after you leave the field and this causes more
problems that it solves.

Thanks,
-DWass


> On Sep 19, 8:42 am, Dianne Hackborn <hack...@android.com> wrote:
>
> > The G1 has akeyboard, so it works as I said -- the IME is not shown by
> > default.  This is a policy decision of the platform.
>
> > On a myTouch, since it doesn't have akeyboard, the IME will be shown by
> > default in various cases (for example when you enter the edit contacts
> > screen) when the app has indicated that is desired with the input options.
>
Re: How to force soft keyboard to be visible? James W 9/22/09 6:27 AM
Well, curiouser and curiouser.

I made a very simple test app running under 1.5 on my Hero, with an
activity showing a single EditText, after the SetContentView() call, I
use the ToggleSoftInput as described above.

When I run it, it does not show the keyboard. However (and I found
this by accident), if you then turn it to Landscape, the keyboard
magically appears. And then if you turn it back to Portrait, the
keyboard is still there. Yet it won't appear initially in the Portrait
mode when the app is first opened, which is the behaviour I am after.

Yet if I start the app in Landscape, the keyboard appears, and is
there when I move back to Portrait.

Here is my code:

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;

public class TestApp extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        InputMethodManager imm =
                (InputMethodManager)getSystemService
(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
                InputMethodManager.HIDE_IMPLICIT_ONLY);

    }
}

and the main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<EditText android:text="EditText01"
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</LinearLayout>

Could someone confirm that this works as expected on non-Hero
hardware? Or anyone have any other ideas as to the weird behaviour?




On Sep 22, 1:16 am, Dianne Hackborn <hack...@android.com> wrote:
> Oh also it doesn't show by default if the IME needs to run in fullscreen
> (typically because the device is in landscape).  Both of these are because
> showing the IME is these cases is much more disruptive than showing it when
> the target window can resize nicely to show all of its important UI in
> conjunction with the IME.
>
> On Mon, Sep 21, 2009 at 10:15 AM, Dianne Hackborn <hack...@android.com>wrote:
>
>
>
>
>
> > All I can say is the edit contacts activity in the standard platform does
> > this just fine, using the standard API.  Either you are doing something
> > different than it, or HTC's IME has some different behavior, but I don't
> > know much about either of those.  Do note that normally the system will not
> > show the IME by default if it has to use panning on the target window
> > (instead of resize), and the only way to get around this would be to
> > explicitly show the IME when you receive focus.
>
> > answer them.
>
> --
> Dianne Hackborn
> Android framework engineer
Re: How to force soft keyboard to be visible? Mike Collins 9/23/09 11:51 AM

Should I take the lack of reply as "not an interesting question",
"no idea" or "we're checking/thinking"?

I would like to have some ammunition when I go up against my
QA people to explain this uncontrolled behavior.

tia,
  mike
Re: How to force soft keyboard to be visible? dwass 9/24/09 12:35 AM
I don't think it is possible that this is "not an interesting
question", based on the amount of activity in this and other similar
posts about how to "hide" or "show" the sofkeyboard programatically.
I've tested a lot of this behaviour on G1 and G2 (Hero) and the
behaviour is either very buggy or there are a lot of subtle
dependencies on other settings that either aren't documented or aren't
intuitively obvious. Let's hope that the experts can ring in with some
comments soon.

-DWass
Re: [android-developers] Re: How to force soft keyboard to be visible? Dianne Hackborn 9/24/09 9:20 AM
How about "no time to get into long involved discussions."
--
Dianne Hackborn
Android framework engineer
hac...@android.com
Re: How to force soft keyboard to be visible? James W 9/24/09 10:14 PM
Dwass, dont know if this helps, but I finally got it to work reliably
for my particular needs.

I have a dialog with a single edit, and I wanted to softkeyboard to
automatically show when the dialog was opened, and be closed when the
dialog was closed. In other words, identical behaviour to the
EditTextPreference when used in a PreferenceScreen.

In my OnCreate() I have:

                InputMethodManager imm = (InputMethodManager)
SingleEditDialog.this.getContext().getSystemService
(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput
(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);

Which shows the keyboard when the dialog is opened. Like you, I had
trouble getting the thing to hide when I close the dialog, I tried
calling toggleSoftInput again but no amount of changing the settings
seems to work. It is not entirely clear what is going on here, and I
am not sure why there is not a .HIDE_FORCED option. It is my app, why
can't I control when the keyboard is shown?

In the end, as I only had one edit field, I was able to use another
method to hide it,

              imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),
0);

where singleedittext is my EditText view.

Incidentally, there doesn't appear to be a corresponding
showSoftInputForWindow() call, though, which is again odd.

Anyway, it now works perfectly. Hope this helps someone else!



On Sep 22, 4:06 pm, dwass <dw...@sharpmind.de> wrote:
> Hi Dianne,
>
> You say that the G1 has akeyboardand so the IME is not shown by
> default. I don't understand that statement. Yes, the G1 has akeyboard, but it isn't always OPEN. Especially if the device is in
> portrait mode, thekeyboardis probably NEVER open. The device should
> be smart enough so that it opens thekeyboardif there is nokeyboard
> open. Either that, or we need a way to show thekeyboardwhen we want
> to (and hide it again when we don't).
>
> My current problem is this: When I start an activity, the first
> EditText field in the layout is focused automatically, but the softkeyboardis not automatically shown. The user must either click (with
> trackball) or touch the field to open the softkeyboard. IMHO the
> developer should be able to say that he wants thekeyboardshown at
> this point.
>
> Any suggestions? I've tried all the "force showkeyboard" suggestions
> and they sometimes do work, but usually you get stuck with thekeyboardbeing shown after you leave the field and this causes more
> problems that it solves.
>
> Thanks,
> -DWass
>
>
>
> > On Sep 19, 8:42 am, Dianne Hackborn <hack...@android.com> wrote:
>
> > > The G1 has akeyboard, so it works as I said -- the IME is not shown by
> > > default.  This is a policy decision of the platform.
>
> > > On a myTouch, since it doesn't have akeyboard, the IME will be shown by
> > > default in various cases (for example when you enter the edit contacts
> > > screen) when the app has indicated that is desired with the input options.
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer- Hide quoted text -
Re: [android-developers] Re: How to force soft keyboard to be visible? Dianne Hackborn 9/24/09 11:56 PM
Those arguments are FLAGS.  Specifying 0 (none of the flags) gives you the default behavior, which for hiding is "always".  The flags are used to limit when it hides to certain situations.  If you just want to force the keyboard to close, use hideSoftInputFromWindow(view.getWindowToken(), 0).

The long press on menu is implemented by just doing toggleSoftInput(view.getWindowToken(), InputMethodManager.SHOW_FORCED, 0);

You probably don't want to use SHOW_FORCED yourself (this is why it isn't the default) because that will leave the IME displayed when the user moves to another activity (even in another application), mostly regardless of what that application's default preference is.

Note also:

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#hideSoftInputFromWindow(android.os.IBinder,%20int,%20android.os.ResultReceiver)

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#showSoftInput(android.view.View,%20int,%20android.os.ResultReceiver)

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#isFullscreenMode()
Re: How to force soft keyboard to be visible? dwass 9/30/09 11:03 AM
Hello James,

Thanks for the code snippet. I've actually tried this.

What device did you test this on? My biggest problem is that when I
find a combination that works on the G1, it doesn't work on the G2
(HTC Hero) or vice-versa. I'm expecting a nightmare when we have 12
devices out there instead of just 2.

-DWass

On Sep 25, 7:14 am, James W <jpbwebs...@gmail.com> wrote:
> Dwass, dont know if this helps, but I finally got it to work reliably
> for my particular needs.
>
> I have a dialog with a single edit, and I wanted to softkeyboard to
> automaticallyshowwhen the dialog was opened, and be closed when the
> dialog was closed. In other words, identical behaviour to the
> EditTextPreference when used in a PreferenceScreen.
>
> In my OnCreate() I have:
>
>                 InputMethodManager imm = (InputMethodManager)
> SingleEditDialog.this.getContext().getSystemService
> (Context.INPUT_METHOD_SERVICE);
>                 imm.toggleSoftInput
> (InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
>
> Which shows thekeyboardwhen the dialog is opened. Like you, I had
> trouble getting the thing to hide when I close the dialog, I tried
> calling toggleSoftInput again but no amount of changing the settings
> seems to work. It is not entirely clear what is going on here, and I
> am not sure why there is not a .HIDE_FORCED option. It is my app, why
> can't I control when thekeyboardis shown?
Re: How to force soft keyboard to be visible? James W 10/1/09 1:09 AM
Dwass,

This is tested on the standard emulator and an unbranded Hero, running
the latest official HTC ROM update, 2.73.

On Dianne's suggestions, I streamlined this a bit, removing the
unnecessary hide flags.

To show the keyboard on the dialog's OnCreate, I use:

            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

To hide it, I use:

                 imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),
0);

As I only have a single edit in my dialog, this works fine.

Note it works the same in the emulator and on the Hero, are you having
different behaviour on your G1?

What is currently working and what isn't? Are you using a dialog or an
activity?
> > Anyway, it now works perfectly. Hope this helps someone else!- Hide quoted text -