0

Fellow Developers, I'm having a challenge that I cannot figure out how to fix and I'm aware that there are thousands of possible questions or hacks connected to my one:

However, almost all of them are connected to check the size of the screen and I can explain the context of my question of why I would like to find a solution.

I have been developing a hybrid app for a while and I have only a minor issue that is this one:

preview

The last row unfortunately in some devices is partially visible and I know what code I should add in jQuery in order to display it properly:

$("input[type=number]").click(function(){
    $("#divCustomTime").css({top: -200, position:'absolute'});
});

However, if the keyboard is dismissed in a different way that is not pressing enter, the location of the div is impossible to relocate to its previous location and I cannot find any way of how to hack it or tricky it, I tried different approaches in order to detect the dismissing event such as:

  • Pressing back button (not triggered at all).
  • Thread for detecting isAcceptingText. It didn't work at all. An example of one of the codes that I tried in C#:

    [Export]
    [JavascriptInterface]
    public void KeyboardStatus()
    {
        var timer = new System.Threading.Timer(callback, (InputMethodManager)context.GetSystemService(Context.InputMethodService), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
    }
    
    private static void callback(object state)
    {
        if ((InputMethodManager)state.IsAcceptingText) {
    
        } else {
            //never happens
        }
    }
    

    Where did I get this idea?

    https://stackoverflow.com/a/52693953/2889347

    I also tried a variation with the method: hideSoftInputFromWindow and it didn't work.

You might ask, why don't you use the option of adjustResize?

It'd be easier to detect and I know, however, the entire app is misconfigured and distorted, up to a point that I should involve a lot of CSS and JS in order to more or less configure it to don't look so terrible, that's why I chose the option of pan and not resize.

Also, I'd like to highlight that I'm developing in Xamarin.Android, but I don't think it might influence the programming language.

Does anyone have any idea how to detect it? Thanks.

Federico Navarrete
  • 2,211
  • 4
  • 32
  • 53

1 Answers1

0

You can't. Not reliably. There is no API to tell when the soft keyboard hides itself, or even when its hidden by the framework. There's a variety of hacks people have tried to use around changing size of the view, but they all have false positives and false negatives, and several features like split screen break it entirely.

Gabe Sechan
  • 77,740
  • 9
  • 79
  • 113
  • Then maybe you could have any idea why this one is always true: (InputMethodManager)context.GetSystemService(Context.InputMethodService).IsAcceptingText because I read it should change. Thanks. – Federico Navarrete Dec 16 '18 at 05:36
  • @FedericoNavarrete isAcceptingText doesn't mean what you think it does. It has to do with the type of input the edit text will accept- if commitText() calls will work, or if you need to try to send keystrokes. It changing from true to false.... I can't think of any situation that would cause that. But it doesn't have anything to do with the keyboard being on screen or the textfield being focused. – Gabe Sechan Dec 17 '18 at 14:01