EditText has focus when Activity starts, but soft keyboard is not shown - android

as mentioned above, the keyboard does not show up, although the EditText is focused (orange border) and the cursor is blinking.
When I click into text field, it opens up, however I want it to be open right when the activity starts.
I tried setting android:windowSoftInputMode="stateVisible" in the activity, I tried showSoftInput(yourTextBox, InputMethodManager.SHOW_IMPLICIT); and also requestFocus().
But no success...
What could be the problem?

Try something like this:
EditText myEditText = (EditText) findViewById(R.id.editPasswd);
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);
Are you testing on emulator? If you do, you should know that keyboard doesn't pop up on emulator :), but it does on a real device
Good luck,
Arkde

Another way to show the keyboard when the Activity is created is to add this code in your AndroidManifest file for the activity which you want to show the keyboard on starts :
<activity android:name=".UserLogin" android:windowSoftInputMode="stateAlwaysVisible"/>

Related

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" />

Unclickable EditText on resume

I currently have an EditText inside a fragmented Tab, When you first enter the view the EditText only works correctly if i use
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
on the view, but it does allow my to hide the keyboard and bring it back be re-clicking.
However if i was to leave this view or if the phone goes to sleep for a moment and comes back the edit text is no longer clickable, I've tried forcing it to be focused using onresume but once you hide the keyboard you cannot regain focus again.
I feel as if i'm missing something regarding EditText Functionality in Fragments but i've had 0 luck finding anything relating to this problem.
Thanks for your time.
Rather then hiding keyboard from code, hide it from manifest on that activity. It will solve your problem i guess.
For hiding from manifest use this code -
<activity
android:name="com.app.xyz.youractivityname"
android:windowSoftInputMode="stateHidden" />
On your onResume you can do this:
EditText someEditText = (EditText)getActivity().findViewById(R.id.someEditText);
someEditText.requestFocus();
InputMethodManager mgr = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(someEditText, InputMethodManager.SHOW_IMPLICIT);

Keyboard not showing on activity start: Android phones

I have an edittext in my activity, and on activity and on create view
I am setting the focus on the activity. while setting focus, I am also
trying to show the keyboard. It works on some devices, but on others it
just doesn't show.
I tried to step through the code and found that the view is not created, when
the show keyboard is called. Maybe that is the reason.
I am not sure what the problem is. Is there a way to make sure, that if a edit text
is in focus, the keyboard shows up on app start.
Thanks,
You can try to show the Soft Keyboard by calling the following line during onCreate:
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
I hope that helps.
In your AndroidManifest.xml, add this attribute to the <activity> tag for the Activity you want the keyboard shown:
android:windowSoftInputMode="stateVisible"

Set android focus on touch?

I have this issue: in my app, when user taps on EditText bar, keyboard pops up. After that, it is impossible to get rid of keyboard. When back button is pressed, whole application just turn off.
How can I make sure, that when user taps on some other object (not EditText), keyboard will be removed? Or at least, how to make it possible to hide keyboard by tapping back button?
Thanks.
in xml for EditText this will make keyboard dismiss when press enter on keyboard
android:imeOptions="actionDone"
You can hide the keyboard simple by overriding onBackPressed in your Activity and using the following code:
InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(anyView.getWindowToken(), 0);
Note that anyView can be any view that is attached to your current window.
You can see it working in my app called Magic Annotator. See method hideSoftKeyboard()

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