I have handled back button to close activity instead of hiding keyboard. It works just fine.
But if device has no hardware buttons software button will show hide keyboard (arrow down instead of back) image when keyboard is open. Of course clicking that down ("back") does close my activity.
This is what i have:
This is what i would like to have instead:
Is it possible to force software back button look like back button (instead of close keyboard) when keyboard is opened?
Related
I've written a sidebar app that is always available and draws directly to the window. If the user has a phone without hardware buttons and he starts typing into an EditText the button bar (that is part of the display because of the missing hardware buttons) with the back/home/recent buttons is hidden.
How can I prevent that?
I've made a custom soft keyboard extended from InputMethodService class, when the user clicks on any EditText, my keyboard will be shown and fill the whole screen (portrait or landscape).
Once I open Twitter application to write a tweet, writing Tweet screen shows up and my keyboard will be shown with no problems.
Once I click back button to hide the keyboard and back to write tweet screen, the keyboard and tweet screen have gone as well! So, any text I've written using my keyboard will be also gone.
I'm not sure if this is Twitter app problem, but I'm not sure how can I solve that? Even if I could handle back button event, what should I do next?
If you also using any soft keyboard, once you click back button, it will hide the keyboard and write a tweet screen as well.
I made a small trick for that, write a text and remove it to get the focus when onWindowShown is called:
getCurrentInputConnection().commitText(" ", 1);
getCurrentInputConnection().deleteSurroundingText(1, 0);
Now everything is working fine :)
When keyboard is open, the icon of the back button is changed to indicate that clicking it will close the keyboard instead of going back.
Back button:
Close button:
Is there a way how to switch from the back icon to close icon programmatically without actually opening the keyboard? We are using a custom keyboard implementation and would like to have the similar behaviour to the native one.
I have an app that contains at some point a FragmentActivity. This FragmentActivity contains some Fragments (FragmentA, FragmentB, etc). On each of these fragments, there are one or more EditText.
I'm trying to handle the keyboard properly. I want to make the Keyboard appear or disappear whenever I want.
For Example, When the FragmentA is created, I want to open the keyboard on an EditText. Then, three options possible for the user :
He clicks on a button that goes to the next fragment
He clicks on the Action Send of the Keyboard(that does nothing (on purpose) but close the keyboard normally) and then he can click on the button from the view
He clicks on the back button of the phone. In this case, it closes the keyboard and then he can click on the button form the view.
My problem is, whenever the user closes the keyboard by clicking on the back button of the phone, Android thinks that he doesn't want to see the keyboard ever in the activity. So when the FragmentB is created, I can't programmatically show the keyboard (Using InputManager btw) on a EditText from this Fragment.
Then, a second problem is when i click on the edittext to get the focus, in Android 4.x, the keyboard shows again, no problems, but with Android 2.x, it's impossible to have the keyboard shown again even if the focus is on the edittext ! It's killing me.
It appears that once the user has explicitly close the keyboard with the back button in one activity (even a fragment activity), you cannot show it again.
Does anyone have a solution ? Maybe playing with the flags in InputManager ? I didn't get all of them and what they do.
Try this:
Show keyboard:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
EditText view = getCurrentFocus();
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
Hide keyboard:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Hope it helps ;)
I've created a soft keyboard inside a v4 support Fragment but I think I'm going about it incorrectly. The keyboard shows up OK, but I can't hide it (the back button closes the programme). Otherwise it works fine. I would like the hardware Back button to be able to close just the keyboard.
myKeyboard = new Keyboard(getActivity(), R.xml.my_keyboard);
myKeyboardView = (MyKeyboardView) getActivity().findViewById(R.id.my_keyboard_view);
myKeyboardView.setKeyboard(myKeyboard);
// this is a custom class to receive soft keyboard events
// just passes on the events to the Activity as normal
keyboardView.setOnKeyboardActionListener(new MyKeyboardListener(getActivity()));
To get the keyboard to show up, I use an OnClickListener on the target EditText with an animation and setting the Visibility to VISIBLE.
Should I be using this approach? I looked for a way to get the keyboard on the backstack but it's not obvious.