Android, only show custom keyboard - android

I have an application where I needed to create a custom keyboard since barcode scanners are classified as hardware keyboards and hardware keyboards disable soft keyboards. The issue is that when no scanner is connected, the built in soft keyboard will be displayed when it's not needed. I have a button to show the custom keyboard which will also hide the default keyboard using
((InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(advText.getWindowToken(), 0);
(advText is an extended version of EditText)
I have tried placing that line of code in the onFocusChanged method of the EditText but nothing happens. If I use setInputType(InputType.TYPE_NULL); the android keyboard never shows, but the EditText doesn't display a cursor or anything that is typed from the custom keyboard (but I do know that keys are being stored since my "done" key sends the text from the EditText elsewhere just fine).
I'm fine with disabling the android keyboard completely for this app, just as long as the EditTexts show cursors and custom keyboard is only shown when using the button.
I have looked at these answers, but no luck finding a solution.
Close/hide the Android Soft Keyboard
How to show soft-keyboard when edittext is focused
How to hide Android soft keyboard on EditText
Edit:
My current solution is to run the hide method inside of the EditText's onCheckIsTextEditor since that seems to run after onFocusChanged, and it seems to be called about every second. But this is a nasty hack since the keyboard still shows for a split second and moves my layouts back and forth. My current test devices consist of the Motorola Photon Q 4G LTE with 4.1.2 and a Honeywell Dolphin 70e Black with 4.0.3

EditText provides this functionality with the flag textIsSelectable in EditText set to true. With this, the cursor will still be present, and you'll be able to select/copy/cut/paste, but SoftKeyboard will never show. Requires API 11 and above.
You can set it in your xml layout like this:
<EditText
...
android:textIsSelectable="true"/>
Or programmatically, like this:
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
For anyone using API 10 and below, hack is provided here :
https://stackoverflow.com/a/20173020/7550472

Edit your <activity> tag in your AndroidManifest.xml and add this attribute: android:windowSoftInputMode="stateAlwaysHidden" see http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Just added that and remove all the other weird things you are doing to hide the soft keyboard.
P.S. You can also enable and disable this feature at runtime. getWindow().getAttributes().softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;

Related

Android: Display custom keyboard then hide soft keyboard?

I have two EditText in my layout, and another layout that contains a custom designed keyboard using ImageButtons. Using these two layouts, I want to:
When the EditText is clicked/touched, hide the default keyboard.
Display the custom keyboard (like a replacement to the default keyboard).
Hide the keyboard after clicking back/return key.
I was able to hide the default keyboard by setting the InputType of the two EditText to NULL. However, it means that the cursor will no longer be visible when EditText is focused. This is part of the specifications of the project.
How do I best approach this problem? What could be a best solution?
Edit: Project specifications were changed. However, I would still love to have the solution or approach to this problem / issue. Thank you very much.

how to set InputType to InputType.TYPE_CLASS_NUMBER in Android Version 7.0 (nougat) and above

I have created Custom Edittext in which i set the InputType as this.setInputType(InputType.TYPE_CLASS_NUMBER); but the problem is it working perfectly on below 7.0(nougat) but above 7.0 it show me alphanumeric keyboard.
one another weird thing happen is when I touch the EditText, I quickly get the soft numerical keyboard, but in less than a second it automatically changes to regular soft keyboard showing all letters. also when keyboard is open, than ill press back button, than keyboard close, but when i re-enter in Edittext. keyboard is not open until i click on onther edittext then current edittext
Is this issue in Nougat or I am doing something wrong
For information i have used code to setSoftInputMode to ADJUST PAN
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
|WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
and to set Numeric keypad use this.setInputType(InputType.TYPE_CLASS_NUMBER);
Edited -
when i remove -
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
|WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
from activity every thing work fine( number keypad open at number edittext , alphanumerical keypad open at alphanumerical edittext ) except the content not goes up-direction means keypad hide edittext(because ignorance of this property SOFT_INPUT_ADJUST_PAN)
Help appreciated thanks
I tried to use setInputType(InputType.TYPE_CLASS_NUMBER) on devices 7+ and didn't see the behaviour that you described. Looking for another thread, runnable or any callback which changing InputType of your EditText after opening or simultaneously.
Try setting softInputMode in your Manifest file, it might give you your desired behavior.
<activity
android:name=".YourActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />

Enter and Return button in a single keyboard in android

I need my soft keyboard input to have both return button AND done button so that the user can write paragraphs in my EditText and click on Done to close the keyboard. Is this possible?
I've tried:
android:inputType="textMultiLine"
android:imeOptions="actionDone"
together but it didn't work.
PS: I'm testing on Samsung keyboard type.
No, I believe it's not possible prior to API level 11 (3.0).
The same issue cropped up here (discussed in the comments to the accepted answer):
Android Soft keyboard action button
From the final comment:
Looking at a few apps on my phone, it seems common to have the multiline box last, with a visible "Done" or "Send" button below it (e.g. Email app).

How do i assert if soft keyboard is invoked when we tap on edit text

I wanted to know if there is a way in which we can assert if the soft keyboard is launched when we tap on edittext using robotium
See correct answer for the question How do I Detect if Software Keyboard is Visible on Android Device?
Also you could use setInputType(0) method to make sure that the keyboard will not be shown while you enter text with robotium.....
solo.getEditText(index).setInputType(0);

Android onscreen keyboard without any other keyboard

I've looked at several questions and come across several posts, but i'm not able to figure out how to do this.
The following picture shows you the basic layout :
I've created a custom numpad and put it up on the repo.
Currently, when the app opens, the edit text has the focus but and anything i enter with the keyboard will go into the edittext box. This part of the functionality works fine.
Problem: When i touch the edittext again, system Input Method with its huge keyboard pops up. How do i completely block it from popping up? Or, can i tell the app to use only my keyboard instead of the system one? (Or is the only way to write a custom ime?)
i cannot use NULL type input at the manifest because doing that makes the caret in the edittext disappear and moreover if there are two edit texts, i wouldnt know which has focus.
Any help would be highly appreciated!
You can do a few things:
Programmatically hide it in the whole app:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Hide it from the view it would be attached to:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
Set the input type of the EditText to 0:
EditText yourEditText=(EditText)findViewById(R.id.editTextConvertValue);
yourEditText.setInputType(0);

Categories

Resources