I want to turn off displaying "Suggested Words" on the soft/virtual keyboard when someone is using my application (only on certain Activities). For the default Android keyboard, this can be found under 'Settings' (under Word Suggestion Settings).
Is there a way to disable it only within your application, without requiring the user to manually go and do it? I basically want the user to type words without providing any hints.
Thanks!
When developing for 2.0+, the supposed way is setting android:inputType="textNoSuggestions" (ref).
Unfortunately, suggestions are still shown on HTC Desire 2.2 (and probably other HTC Sense devices as well).
Using android:inputType="textVisiblePassword"will not help as well as the software keyboard by HTC won't allow you to switch languages.
So I stick to android:inputType="textFilter" to disable suggestions.
You can disable suggestions on the Soft Keyboard by adding the following line in the xml -
android:inputType="textNoSuggestions"
However according to this article, it may or may not be supported by the IME (the keyboard).
If this issue occurs, the below method works for sure -
android:inputType="textNoSuggestions|textVisiblePassword"
This works for me with the stock keyboard, even on HTC with 2.2
final EditText et = (EditText) findViewById(R.id.SearchText);
et.setInputType(et.getInputType()
| EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS
| EditorInfo.TYPE_TEXT_VARIATION_FILTER);
On my 6P running Nougat, nothing worked. While it is empty the suggestion bar stays up because it has the microphone icon on the right side.
In order to get rid of that, I used fingerup's suggestion in one of the comments and it worked!
So I decided to write an actual answer so people don't miss it.
To recap here's what I've used:
android:inputType="textNoSuggestions|textFilter|textVisiblePassword"
android:privateImeOptions="nm"
inputType="textNoSuggestions|textFilter|textVisiblePassword" prevents suggestions, and privateImeOptions="nm" (stands for "no microphone") prevents the bar from showing up because it still would since the mic button is in it.
So it is necessary to use both attributes because if all you do is specify no mic then the bar still shows up with recommendations.
Thx again to fingerup for mentioning the nm trick. ;)
There are two ways that I know of to disable the auto-complete. One way is through the XML by setting the android:inputType="textVisiblePassword" in the layout xml.
The other way is through code such as the following
EdtiText editTextBox = findViewById(R.id.myEditTextView);
editTextBox.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
I was facing the same issue on Samsung devices using:
android:inputType="textNoSuggestions|textFilter|textVisiblePassword"
only after setting the inputType to password and visiblePassword worked for me:
android:inputType="textPassword|textVisiblePassword"
android:inputType="textPhonetic" hides soft keyboard suggestions on Android 1.6.
hope this works for you,
editText.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES|InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
If you are using InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS in activity, it will work fine.
In case of DialogFragment, you should place InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS at
onActivityCreated() handler as below :-
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
EditText editTextUsername = (EditText)dialogView.findViewById(R.id.txtUsername);
editTextUsername.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
Related
So I want to have a keyboard in my app that has emoji just like Whatsapp or Hangouts. How can I do that? I want to leave my key keyboard as it is I just want to add tabs to put emojis. I would think it would be easily supported by the soft keyboard but I can find nothing so far. Anyone could tell how to do it?
UPDATE:
The keyboard with emoji is included in Android KitKat and can be accessed by long pressing the new line button in the keyboard. The Hangouts keyboard however has the emoji icon visible instead of the "new line" key. If someone knows how to make this the default (either in layout or programmatically) I will take that as the correct answer.
As #dbar pointed out, the answer is:
android:inputType="textShortMessage"
But in my case, I was already using textMultiLine, so I had to use the both of them together:
android:inputType="textMultiLine|textShortMessage"
Looks like this:
I'm not sure about the Exact android version, but this should work only on Android 4.1 and above
Finally the answer was:
android:inputType="textShortMessage"
The new line key becomes a key to take out the emoji keyboard. The only quibble is the 'new line' key from the keyboard disappears with this configuration (before you could long press to choose between emoji/new line but now it's only emoji).
In Google Hangout, the emoji button is not on the keyboard (at least on my phone which is already using a third party keyboard), it's inside of the TextEdit box, and so it's part of the application itself (Gabe, I'm talking about the latest Google Hangout on top of KitKat with emoji support, all the current screenshots I found of Google Hangout do not show what I'm seeing on my phone, so this must be a very recent feature).
This is actually pretty easy to do, placing an ImageButton to the right of a TextView inside a RelativeLayout (the RelativeLayout which is made to look like a TextView with a custom background).
Then, it's just a matter of hiding the keyboard when clicking on that ImageButton and replacing it with a panel full of emojis when that happens (like in this open source emoji android keyboard, which is under a creative commons non-commercial license).
There is no functionality to add tabs to any generic keyboard. Certain keyboards may support it, but it isn't a common feature. You could write your own fully custom keyboard, but that's a lot of work and will piss off many users.
Also, I'm not sure what you mean about by like in hangouts. I use hangouts- it doesn't do anything odd with my keyboard. It stays as Swype, there's no special emoji tab. It may be a feature of your favorite keyboard based on the input type (I assume both use input type textShortMessage). But it isn't a generic feature.
in my app I disabled the keyboard (I use now my custom keyboard) using this code:
editText.setInputType(InputType.TYPE_NULL);
Now, my problem is that the text cursor does not appear anymore in the edit text. What should I do? Any suggestion would be very appreciated.
There is an Issue opened in bug tracker Issue opened in bug tracker for this.
One of the users suggests the approach which works on "most" devices.
Briefly, all you have to do is call:
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
for your EditText view (after you called editText.setInputType(InputType.TYPE_NULL);).
You should probably also set:
editText.setTextIsSelectable(true);
in order for text to be selectable (though in does not seem to work properly with Samsung Galaxy SIII). This method is only available starting from HONEYCOMB (api11) so keep that in mind when developing for older Android versions.
Also it is stated that your EditText should not be the first view to receive focus when activity starts (if it is - just requestFocus() from another view). Though I (personally) have not experienced any problems with this.
Rather than just using a custom view for your custom keyboard, why not implement a full-fledged IME? That will solve your cursor problem, and even make your keyboard available outside your app (if you want).
This answer has a couple useful links if you want to do that:
How to develop a soft keyboard for Android?
I really wouldn't suggest this. Writing a good full fledged IME is really hard. In addition, users come to expect functionality from their keyboard (auto-correct, Swyping, next word prediction, the ability to change languages) that you won't have unless you spend months on the keyboard itself. Any app that wouldn't allow me to use Swype would immediately be removed (bias note: I worked on Swype android).
But if you want to integrate fully with the OS as a keyboard, you're going to have to write an InputMethodService. Your keyboard would then be selectable by the user in the keyboard select menu, and usable for any app. That's the only way to get full OS integration, otherwise you'll need to really start from scratch- writing your own EditView. Have fun with that, getting one that looks nice is decidedly non-trivial.
Also, setting input type null won't disable most keyboards. It just puts them into dumb mode and turns off things like prediction.
I tried the below answer and it worked, but take care that
1) EditText must not be focused on initialization
2) when your orientation changes while the user's focus is on the editText, the stock keyboard pops up, which is another "solvable" problem.
This was mentioned in a previous answer but take care that you MUST make sure your editText element do not get focus on instantiation:
https://code.google.com/p/android/issues/detail?id=27609#c7
#7 nyphb...#gmail.com
I have finally found a (for me) working solution to this.
First part (in onCreate):
mText.setInputType(InputType.TYPE_NULL);
if (android.os.Build.VERSION.SDK_INT >= 11 /*android.os.Build.VERSION_CODES.HONEYCOMB*/) {
// this fakes the TextView (which actually handles cursor drawing)
// into drawing the cursor even though you've disabled soft input
// with TYPE_NULL
mText.setRawInputType(InputType.TYPE_CLASS_TEXT);
}
In addition, android:textIsSelectable needs to be set to true (or set in onCreate) and the EditText must not be focused on initialization. If your EditText is the first focusable View (which it was in my case), you can work around this by putting this just above it:
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >
<requestFocus />
</LinearLayout>
I am developing an android phonegap app. i created a popup using HTML, which contains two edit fields for "username" and "password". when these fields receives focus, the soft keyboard appears and hides immediately. Can anybody say why it behaves like this.
Thanks in advance
it must be losing focus right after too for some other reason I would suspect.
Try to add android:windowSoftInputMode="adjustResize" on your Android manifest file.That worked for me.
It's a late answer but will be helpful for someone else.
very simply:
inputField.setImeOptions(EditorInfo.IME_ACTION_DONE);
used to make my soft keyboard show the "done" key instead of carraige return.
Since I updated my phone (Samsung Galaxy S) to gingerbread this line of code is having no effect.
Any ideas?
I have seen this problem also and I believe it occurs when you have not set an inputType. Actually all imeOptions properties (along with a few others) get ignored completely if the inputType is set to EditorInfo.TYPE_NULL (the default).
So give one of these a shot (I picked next but you can put any type in):
XML:
android:inputType="text"
android:imeOptions="actionNext"
JAVA
text.setInputType(EditorInfo.TYPE_CLASS_TEXT);
text.setImeOptions(EditorInfo.IME_ACTION_NEXT);
And if you really want to go nuts you can use setImeActionLabel('Add', SOME_ID) and completely configure the action key (there are xml equivalentes also).
That being said. I could be completely wrong about your individual device but I figured this is easy to test and seems to always solve my problem so I should share.
I have been researching the same problem. The IME (input method editor) on your device is it at fault and will not display the done button in the soft keyboard or the next button for that matter. HTC sense has its own soft keyboard and does not recognize ime directives. there are others and your samsung obviously is one. this is the first time I have ran head long into android fragmentation.
I did try setting it in XML, inflating, and creating a helper class, and a heap of other things. I was relieved to find out that it simply does not work.
So now instead of the keyboard editor completing the entry we must add a done button. I'm adding it to the end of my edit text using a relative layout to align them. Ill leave the IME code for those that have that functionality.... this is the is the only quick solution, the other being writing a entire custom soft keyboard for your app.
I've checked inside the method TextView.setInputType and at the end of this method, InputMethodManager restarts the keyboard. So this is the trigger to change the imeOptions, not InputType.TYPE_NULL.
private void changeInputTypeAndImeOptions(EditText fieldValue, int inputType, int imeOption) {
if (inputType == InputType.TYPE_NULL) inputType = fieldValue.getInputType();
fieldValue.setImeOptions(imeOption | EditorInfo.IME_FLAG_NO_FULLSCREEN);
//Makes the trigger for the imeOptions to change while typing!
//fieldValue.setInputType(InputType.TYPE_NULL);
fieldValue.setInputType(inputType);
InputMethodManager imm = (InputMethodManager)
mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) imm.restartInput(fieldValue);
}
NOTE:
Setting the setInputType with same previous value, doesn't give any effect so better to restart imm (this doesn't close the kb, only refreshes the buttons).
Also fieldValue.setInputType(InputType.TYPE_NULL); has a bad effect the return button is visible during the multiple set, that's why is commented and it should be removed. Better restart the kb with imm.
In my app I want an EditText that doesn't accept any input, i.e. android:editable="false" in XML layout or setKeyListener(null) in code.
I only want to add characters in a very controlled manner, and so I always add it programmatically with setText() and I don't want any virtual keyboard to show up. However, I still need a visible cursor in the EditText so that the user will know where the programmatic input will be inserted.
This was very easy to implement (android:editable="false") until Android 4.0. In 4.0, the cursor was apparently removed. I've tried android:cursorVisible="true" but it doesn't work.
Does anyone know how to both have a visible cursor and still suppress input in Android 4.0? Really grateful for any help here.
Please Try
android:clickable="false"
Set android:focusable=false in your EditText.
I had similar problem. Try using:
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
it worked for me. For more details see http://code.google.com/p/android/issues/detail?id=27609