Android how to show keyboard

Android: How to make the keypad always visible?

In android, how do we make the device keypad always visible in the application? The top portion displays the content the application wants to render and bottom portion displays the keypad always.

3 Answers 3

Add android:windowSoftInputMode=»stateAlwaysVisible» to your activity in the AndroidManifest.xml file:

In my test app this shows the keyboard on starting of the application although it isn’t fixed there but can be dismissed by pressing the back button.

To make sure the keyboard is always visible you might have to create your own keyboard as part of the UI of your application. Here is a tutorial to show you how to do this with KeyboardView: http://www.fampennings.nl/maarten/android/09keyboard/index.htm

You must have an EditText in your layout and that need to extent EditText base class. then Override onKeyPreIme() method, and return True. Now your keyboard will be always visible and can’t be dismissed by Back key.

Caution: Because of your onKeyPreIme() method returns true you can’t exit your app using back key.

I found a way that works for me to keep the soft keyboard visible after an edit in my myEditText field of class EditText . The trick is to override the onEditorAction method so that it returns true

or else have onEditorAction return true only after the «Done» key-click ( IME_ACTION_DONE ) otherwise false

(see also this answer on the onEditorAction method)

Adding android:windowSoftInputMode=»stateAlwaysVisible to the Manifest file helped to have the soft keyboard shown at activity start but it didn’t prevent it from disappearing again whenever the «Done» key was clicked after an edit.

Источник

How to display custom keyboard when clicking on edittext in android

I have a custom keyboard in my application. question is How to didplay this keyboard when click on the edittext.I an using setonfocuschangre listener ,now the custon keyboaed appears when the edittext focus is changed.but i want to show this keyboard whenever i click on the edittext..one info I forget to put here the edittext is within the fragment.

6 Answers 6

I created a Custom Keyboard in my application using Keyboard tag. I am adding this keyboard in a RelativeLayout on my screen like.

If you want to use this CustomKeyboard on one or more than one EditText then you have to use below code :

You can try something like this

For more info check here

Use getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); to disable the default keyboard and then set a click listener to show your own keyboard

Use onClickListener like following:

Or you can do this:

Initiate the InputConnection of your edit text and create methods to delete and enter texts when your custom keyboard view is performed with any user actions.

Declare inputConnection on the activity onCreate method as below;

Читайте также:  Создаем анимацию для андроид

When you enter any text execute the below code.

When you click the clear / backspace button execute the below code.

Источник

Android: show soft keyboard automatically when focus is on an EditText

I’m showing an input box using AlertDialog . The EditText inside the dialog itself is automatically focused when I call AlertDialog.show() , but the soft keyboard is not automatically shown.

How do I make the soft keyboard automatically show when the dialog is shown? (and there is no physical/hardware keyboard). Similar to how when I press the Search button to invoke the global search, the soft keyboard is automatically shown.

28 Answers 28

You can create a focus listener on the EditText on the AlertDialog , then get the AlertDialog ‘s Window . From there you can make the soft keyboard show by calling setSoftInputMode .

For showing keyboard use:

For hiding keyboard use:

You can request a soft keyboard right after creating the dialog (test on SDK — r20)

I had the same problem and solved it with the following code. I’m not sure how it will behave on a phone with hardware keyboard.

Snippets of code from other answers work, but it is not always obvious where to place them in the code, especially if you are using an AlertDialog.Builder and followed the official dialog tutorial because it doesn’t use final AlertDialog . or alertDialog.show() .

Is preferable to

Because SOFT_INPUT_STATE_ALWAYS_VISIBLE will hide the keyboard if the focus switches away from the EditText, where SHOW_FORCED will keep the keyboard displayed until it is explicitly dismissed, even if the user returns to the homescreen or displays the recent apps.

Below is working code for an AlertDialog created using a custom layout with an EditText defined in XML. It also sets the keyboard to have a «go» key and allows it to trigger the positive button.

Well, this is a pretty old post, still there is something to add.
These are 2 simple methods that help me to keep keyboard under control and they work just perfect:

Show keyboard

Hide keyboard

I know this question is old by I think using an extension function is a prettier way to show keyboard for an edit text

here is the method I use to show keyboard for an edittext.

kotlin code: just need to call edittext.showKeyboard()

the java code:

Let me point some additional info to the solution of yuku, because I found it hard to get this working! How do I get the AlertDialog object from my AlertDialog.Builder? Well, it’s the result of my alert.show() execution:

Take a look at this discussion which handles manually hiding and showing the IME. However, my feeling is that if a focused EditText is not bringing the IME up it is because you are calling AlertDialog.show() in your OnCreate() or some other method which is evoked before the screen is actually presented. Moving it to OnPostResume() should fix it in that case I believe.

Yes you can do with setOnFocusChangeListener it will help you.

If anyone is getting:

Cannot make a static reference to the non-static method getSystemService(String) from the type Activity

Try adding context to getSystemService call.

Читайте также:  Settext android studio для чисел

The original question concerns Dialogs and my EditText is on a regular view. Anyhow, I suspect this should work for most of you too. So here’s what works for me (the above suggested highest rated method did nothing for me). Here’s a custom EditView that does this (subclassing is not necessary, but I found it convenient for my purposes as I wanted to also grab the focus when the view becomes visible).

This is actually largely the same as the tidbecks answer. I actually didn’t notice his answer at all as it had zero up votes. Then I was about to just comment his post, but it would have been too long, so I ended doing this post anyways. tidbeck points out that he’s unsure how it works with devices having keyboards. I can confirm that the behaviour seems to be exactly the same in either case. That being such that on portrait mode the software keyboard gets popped up and on landscape it doesn’t. Having the physical keyboard slid out or not makes no difference on my phone.

Источник

Android — Programmatically Hide/Show Soft Keyboard [duplicate]

First thing first I already saw this thread. I tried the accepted methods given there, but nothing worked for me.

I have two screens in my app.

  • First one has 2 EditText — One for username and one for password
  • Second one have one ListView, and an EditText — to filter the listView

In my first screen, I want username EditText to have focus on startup and the Keyboard should be visible. This is my implementation (simplified by removing unnecessary/unrelated code).

Well, the keyboard is not showing at startup. And my design badly requires a keyboard there.

Now on to second page. As I already mentioned, I have a listView and EditText there. I want my keyboard to be hidden on startup only to appear when the user touches the editText. Can you believe it? whatever I tried soft Keyboard is showing when I load the activity. I am not able to hide it.

  1. On Login Page (first Page) I want my keyboard to be visible on startup.
  2. On SecondPage I want the keyboard to be hidden first, only to appear when the user touches editText

And my problem is I am getting the exact opposite on both occasions. Hope someone faced this issue before. BTW I am testing on the simulator and HTC Desire phone.

Well, I got it working, with the help of all my friends here.

1. To Show keyboard on startup

Two answers worked for me. One provided by @CapDroid, which is to use a handler and post it delayed..

The second answer is provided by @Dyarish, In fact, he linked to another SOF thread, which I haven’t seen before. But the funny thing is that this solution is given in the thread which I referenced at the start. And I haven’t tried it out because it had zero votes in a thread where all other posts have plenty of votes. Height of foolishness.

Читайте также:  Zinnia journal and planner для андроид

For me, the second solution looked neat, so I decided to stick with it..But the first one certainly works. Also, @Dyarish’s answer contains a clever hack of using a ScrollView below EditText to give EditText the focus. But I haven’t tried it, but it should work. Not neat though.

2. To hide keyboard at activity start

Only one answer worked for me, which is provided by @Dyarish. And the solution is to use focusableInTouchMode settings in XML for the layout containing the EditTexts. This did the trick

Anyway, I end up using Dyarish’s answer in both cases. So I am awarding the bounty to him. Thanks to all my other friends who tried to help me.

Источник

Open soft keyboard programmatically

I have an activity with no child widgets for it and the corresponding xml file is,

and I want to open soft keyboard programmatically while the activity gets start.and what I’ve tried upto now is,

Give me some guidance.

25 Answers 25

I have used the following lines to display the soft keyboard manually inside the onclick event, and the keyboard is visible.

But I’m still not able to open this while the activity gets opened, so are there any solution for this?

In your manifest file, try adding the following to the that you want to show the keyboard when the activity starts:

This should cause the keyboard to become visible when the activity starts.

For more options, checkout the documentation.

Please follow the below code. I am sure your problem will be solved.

All I needed was to expose the keyboard, in a very precise moment. This worked for me! Thanks Benites.

And in the very precise moment:

I have used the following lines to display the soft keyboard manually inside the onclick event.

Put that in onResume method:

the runnable is needed because when the OS fires the onResume method you can’t be sure that all the views where draw, so the post method called from your root layout makes it wait till every view is ready.

in onCreate method of activity or onActivityCreated of a fragment

seems like this is working

seems this works better: in manifest:

seems the manifest working in android 4.2.2 but not working in android 4.0.3

Kotlin

I have used like this to show the soft keyboard programatically and this is worked for me to prevent the auto resize of the screen while launching the keyboard.

In manifest:

In XXXActvity:

I assume this will save others time to search for this problem.

I used it as singleton like:

Use it in your activity like:

And you call this method like this:

Use above code in onResume() to open soft Keyboard

InputMethodManager.SHOW_FORCED isn’t good choice. If you use this setting you should manage hiding keyboard state. My suggestion is like this;

Also, you can focus on view (usually EditText) taking parameters it. This makes it a more useful function

Источник

Оцените статью