Why does toggleSoftInput() work, but showSoftInput() doesn't? - android

I have an extremely simple linear layout view containing nothing but an EditText. When I open it up I want the soft keyboard to open too.
Android documentation says to use showSoftInput(), but nothing happens when I do. But if I replace that with toggleSoftInput(), the keyboard shows up properly.
Because toggleSoftInput() has been deprecated, I'd like to get my code working with showSoftInput(). What else must I do to make this work?

Related

UI Automator with custom keyboard. Find exact keyboard button and click it

I'm trying to write UI automation tests for the custom soft keyboard using UI Automator and\or Espresso. Tried different ways but I can't find a proper solution to "find the exact button on the opened keyboard and click it".
Problems:
UIAtomator's UiDevice.findObject(By.text("Q")).click() doesn't find Q button on keyboard.
Espresso's onView(withText("Q")).perform(click()) doesn't find the button either.
For now, it looks like the only way to click button is to measure XY coordinates based on screen height and keyboard height. But this solution is ugly and not persistent.
typeText("text")and uiObject.text = "text" don't work since it bypasses keyboard input.
Was anyone working with custom keyboards? Please help.
Since you're building a custom soft keyboard then I expect you're using a KeyboardView. KeyboardView draws the keys using a canvas therefore it is not possible to get the resource ids of the keys... so no chance to find them through the UiDevice's findObject method.
Considering the KeyboardView class is deprecated since API 29, a possible solution will be to reimplement your own KeyboardView (as suggested here) and use AccessibilityNodeInfo class to build virtual elements (one for each key) that will be included into the view hierarchy.
The best solution in my opinion would be to create your own TCP server to solve this issue. Please refer to this link to find out how: https://ops.tips/blog/a-tcp-server-in-c/

keyboardView with webview

I´m working on a custom system keyboard based on this tutorial. Which creates a basic custom keyboard. How would I be able to add a webview over the keyboard? Basically I want a small row like this on top of the keyboard, but instead emojis, I want a (small) webview to be there.
I have tried to add a webview decleration in the number_pad file without it making any differanse, tried the same with keyboard_view, but it also din´t work. I tried to change webview to textview to see if it would show anything then, but still nothing. Then I thought I might be able to use a popupWindow, but I wasn't able to get that to work either :/.
Any ideas? Any tips? i´m new to android programing so a little code POC with the answer would be nice.

Properly Scrolling an EditText into view when focused

I've got an EditText, which is ultimately inside of a ScrollView. I've implemented a comment feature which takes you to a new activity, and automatically places focus in the edit text so that the user can immediately start writing his comment.
Unfortunately, it doesn't quite scroll the edittext into view, as you can see in the screenshot below:
I would like to see something more like this, where the EditText comes completely into view (see below). I already looked at the android:WindowSoftInputMode, and it seems like the default values should work ... and indeed, it does mostly work because it does scroll, just not enough.
So is there anything I can do to get the desired behavior? Thanks!
is your min SDK 3?
check this
Hope you have tried android:windowSoftInputMode="adjustPan" and check this.
I would give this a go.
You could also try to programatically use this on the onCreate() method of you activity.
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
"SOFT_INPUT_ADJUST_PAN" adjustment option is set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible.

dismiss a view from class extended by InputMethodService

I am created a custom keyboard. The keyboard is NOT an extension of the Keyboard class and does not use the Keyboard View class either. I have successfully created my keyboard so that it popups up. The keyboard is a LinearLayout I created from an xml file. Here is the problem: I can't get rid of it.
If it was an extension of KeyboardView, I would use
keyboard.closing();
but since its a LinearLayout, I don't have that method.
I then tried
keyboard.removeView(keyboard);
I didn't expect this to work, and it didn't.
Finally, I tried
keyboard.removeAllViews();
in hopes that it would sort of leave keyboard on the screen, but no one would no if all the views were removed. This did not work either.
Any suggestions?
Well if keyboard is the View you want to hide, try calling keyboard.setVisibility(View.GONE). If you want to remove it entirely you would have to find the parent view of keyboard and call removeView(keyboard) on that. I think the first approach is simpler though, depending on what you want.

"adjustResize" Android

I have an app that runs fullscreen by using:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Because of this the layout, android:windowSoftInputMode="adjustResize" is not working properly, i.e. it dose not resize.
Is there any way to get over the problem?
FYI: This is an existing AOSP (Android Open Source Project) bug: http://code.google.com/p/android/issues/detail?id=5497
Ideally this bug would be fixed, but until then here are a couple thoughts of how it could be worked around. Since I have no idea what application scenario this pertains to, these may not be very applicable.
In agreement with my best interpretation of the previous answer, design your layout so that adjustPan works ok with it. The first thing I can think of here is not having any headers or footers that are intended to remain on screen when the keyboard is up.
Don't use FLAG_FULLSCREEN with a layout that can accept text input. Possibly it wouldn't be a big deal to show the status bar when accepting input. However, for something that views content with embedded input fields (like a web browser) that has a fullscreen mode, this doesn't make much sense at all.
Implement adjustResize-like behavior of your own. I'm not sure how well this would work, but possibly you could write a subclass of whichever class is causing the keyboard to be shown (ex: EditText) where you either track when the keyboard is shown or take over the calls to show and hide the keyboard (overriding at least onKeyUp and onTouchEvent). When shown, resize your content - possibly with a best guess of the softinput height, since users can install different soft input methods. I believe this would be technically difficult and not reasonable to attempt without extreme need.
Instead of android:windowSoftInputMode="adjustResize" you can try with android:windowSoftInputMode="adjustPan"

Categories

Resources