Can not get Keyboard in android - android

I create EditText. How to get Keyboard object and set myself setting. For example set first letter in upper case when I focused on EditText.

You can simply add 'android:inputType="textCapSentences"' to you EditText element in you XML layout. as example:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:padding="8dp"
android:textSize="18sp"
android:inputType="textCapSentences"/>
It could not be applied automatically on a Emulator like GenyMotion, but if you test it on a device it would.
Good luck

Related

Displaying keyboard below the the selected line using multi-line TextField

so I've got the following layout with the following TextInputEditText :
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/note"
android:layout_marginTop="#dimen/layout_margin_default"
app:startIconDrawable="#drawable/baseline_notes_24">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
/>
</com.google.android.material.textfield.TextInputLayout>
Right now, when I select to write inside the TextInputEditText the keyboard automatically displays below the TextInputEditText:
Now, what I want to is that rather displaying the keyboard below the TextInputEditText, I want the display to keyboard below the current "selected" line, which should look like this:
Example video how it should look like:
https://jumpshare.com/v/TAO6jo1jdnRZDhYyzrkY
How can this be solved in the right way?
I've tried using android:windowsoftinputmode, but I couldn't find the appropriate attribute.
I'm assuming there is not much leeway when it comes to the displaying the keyboard?

Android XML - EditText word-wrapping without newlines

I have this stupid and seemingly trivial problem with the properties of an EditText.
The properties I am trying to achieve for the EditText, are the following:
The contents of the view should NOT contain newlines. It can be text, numbers, symbols, but no newlines.
The soft keyboard should NOT display the enter button because of the above. It should instead display something like "Send" or "Done".
The contents of the view should NOT continue horizontally when reaching the edge of the screen. Instead I want to wrap the text, displaying it on multiple lines.
I have tried many different combinations, but I can not achieve this combination.
What I currently have is this, which is inside a RelativeLayout:
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#id/preparation_text"
android:hint="#string/comment_hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"/>
It achieves 2 of 3. No newlines possible, keyboard displays "Send" rather than the enter-key for me, but the text continues on one line.
Changing inputType="text" to "textMultiLine" wraps text correctly on multiple lines, but also overrides the keyboard to always display the enter button.
I have tried different solutions around the Internet, including setting the properties maxLines="4", singleLine="true" and possible others that I have forgotten again.
I can not find a combination that works.
Output:
Exp:
The op is on right track. I did some research found that some options gets ignored which are specified in XML. but if the same options are set in code then it should do the trick. I used the same XML fragment specified in the question.
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="80dp"
android:hint="hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"
/>
And by adding the following lines in the code, it helped in achieving what you want.
edit_text.setMaxLines(Integer.MAX_VALUE);
edit_text.setHorizontallyScrolling(false);
textShortMessage is the inputType that you are looking for:
<EditText
android:id="#+id/commentEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:gravity="left"
android:text=""
android:hint="hint"
android:textSize="16dp"
android:textColor="#android:color/black"
android:lineSpacingExtra="0dp"
android:lineSpacingMultiplier="1"
android:background="#android:color/white"
android:selectAllOnFocus="true"
android:inputType="textShortMessage|textMultiLine|textCapSentences"
android:singleLine="false" />
Refere to this to prevent paste function. To prevent pasting a new line.
Please use android:imeOptions="actionSend"
to solve your problem.
I have the same issue a long time ago, you have to programmatically change Edittext property on OnCreate().
So in XML, create your Edittext like this
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="80dp"
android:hint="Comment here"
android:maxLength="400"
android:inputType="textMultiLine" />
And on onCreate() (I wrote in kotlin not Java)
comment_box.imeOptions = EditorInfo.IME_ACTION_SEND
comment_box.setRawInputType(InputType.TYPE_CLASS_TEXT)

How to make Android EditText expand vertically when full

I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
Yes, this actually involves two things:
Making the EditText accept multi-line input.
Having its height grow as more text lines are added.
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(Be mindful of the difference between textMultiLine and textImeMultiLine).
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.
<EditText
...
android:layout_height="wrap_content"
android:inputType="textImeMultiLine|textMultiLine"
... />
In my case I have multiline text, but it showed one line and a keyboard:
Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.
Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:
In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.

Android EditText doesn't show keyboard hint if use more than one inputType attribute

I'm trying to have an Edit text with keyboard hints and auotcorrection for words (such as when you write a message in whatsapp).
This is my code:
<EditText
android:id="#+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="#color/white"
android:ems="10"
android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete"
android:scrollHorizontally="false"
android:hint="#string/note_content"
android:textColor="#color/black_text" />
According with the documentation it should work but it doesn't.
I've also tried using the deprecated android:autoText="true".
I need all the functionallity specified in the InputType
Edit:
After some try I discovered that if I set only one attribute without problem but if I set all of what I need nothing work correctly.
Edit 2:
What I want to obtain is something like the Whatsapp editbox where you write your message.
Maybe it has to do with the input type, have you tried single combinations?
Using a combination of textAutoCorrect and textAutoComplete might not always work

How can I use a custom font in the input area of an input method?

We're developing an app where we need to use a custom font (a Typeface loaded from the app's assets) in an EditText. The Android input method docs state the following:
When input focus moves into or out of an editable text field, Android shows or hides the input method (such as the on-screen keyboard) as appropriate. The system also makes decisions about how your UI and the text field appear above the input method. For example, when the vertical space on the screen is constrained, the text field might fill all space above the input method.
It's the part in bold that is tripping us up. The phrase “the text field might fill...” appears to be misleading, in that the text field that's used is not the EditText that we set up with our custom font. (NOTE: the answers so far all explain how to set a custom font in an EditText. We already are setting a custom typeface in the EditText. Please read the question carefully before answering.) Here's a screenshot with the input method hidden:
Here's what happens when the soft keyboard is showing and vertical space is constrained:
As you can see, the font in the text field above the input method is not our custom font (I'm guessing it's the system's default Roboto font). This is happening for every soft keyboard we've tried as the input method.
I want to emphasize that when space is constrained, this view above the keyboard is generated internally by the system, not by any of our code.
The main question is: Is there a way (and, if so, what is it?) to control the appearance of this (for lack of better terminology) proxy view—at a minimum to get it to use our custom font?
It would be an added bonus if we could also control the layout and appearance of the entire proxy area above the keyboard (including the "Done" button). We are using a variation of the technique described in this thread to have our activity use a locale different from the one set in the system, but the activity's locale clearly isn't being applied here. (If it were, the button would be on the left and would read "בוצע", as does happen if I change the device's locale to Hebrew. [EDIT: I can get the correct button label by using the android:imeActionLabel attribute on the EditText. However, I don't know how to control the layout directionality.])
EDIT Per request, here's how I'm constructing my dialog (relevant parts excerpted from a DialogFragment):
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dlg = new Dialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar);
dlg.setContentView(R.layout.edit_note_dialog);
mAnimator = (ViewAnimator) dlg.findViewById(R.id.animator);
final Typeface hebrew = SystemData.getHebrewFont();
mNoteEditor = (EditText) dlg.findViewById(R.id.note_field);
mNoteEditor.setTypeface(hebrew);
// etc. (setting fonts for other elements, adding listeners, etc.)
}
And here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/animator"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="#string/loading" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:gravity="center"
android:text="#string/edit_note_title"
android:textColor="#android:color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/citation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/actions"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp" >
<Button
android:id="#+id/cancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="center"
android:minWidth="32dp"
android:text="#string/cancel"
android:textSize="#dimen/nav_interior_item_size" />
<Button
android:id="#+id/close"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="center"
android:minWidth="32dp"
android:text="#string/save"
android:textSize="#dimen/nav_interior_item_size" />
</LinearLayout>
<Button
android:id="#+id/undo"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_margin="5dp"
android:text="#string/edit_note_undo"
android:textSize="#dimen/nav_interior_item_size" />
<Button
android:id="#+id/redo"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="5dp"
android:text="#string/edit_note_redo"
android:textSize="#dimen/nav_interior_item_size" />
<EditText
android:id="#+id/note_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/actions"
android:layout_below="#+id/citation"
android:focusableInTouchMode="true"
android:gravity="top"
android:hint="#string/edit_note_hint"
android:imeActionLabel="#string/done"
android:inputType="textMultiLine|textNoSuggestions"
android:lineSpacingMultiplier="1.2" />
</RelativeLayout>
</ViewAnimator>
It would be simple if you had an instance of InputMethodService.
There is a way to set a theme or even set extracted view.
The problem is you have to create a custom implementation of Input Method and users will have to select it in the system settings.
Update:
You can try with:
android:windowSoftInputMode="adjustResize"
make the view scrollable
or
use IME_FLAG_NO_EXTRACT_UI
set an OnEditorActionListener on the EditText to have an action button on the keyboard.
create custom layout or hide/show elements when screen's height is too small. For example hide buttons at the bottom and show buttons on right side. It can look similar to the default extract view.
layout listener for the dialog or EditText:
mViewContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
//unregister the layout listener if needed.
int heightPixels = mViewContainer.getHeight();
Resources resources = mContext.getResources();
int heightDip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightPixels, resources.getDisplayMetrics());
if (heightDip < MIN_HEIGHT) {
mBottomButtons.setVisibility(View.GONE);
mSideButtons.setVisibility(View.VISIBLE);
} else {
mBottomButtons.setVisibility(View.VISIBLE);
mSideButtons.setVisibility(View.GONE);
}
}
});
Changing the visibility to GONE will request relayout and the listener will run again what can lead to a loop.
The only way I can see is to disable the fullscreen editing mode for your EditText that automatically kicks in when your EditText is not tall enough.
mNoteEditor.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
You can fix the dialog resizing issues with
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Your dialog layout should probably be enclosed in a ScrollView.
I think as other have stated this is unfortunately up the IME and may not be possible through supported APIs.
Beware, hacky and untested solution incoming:
Digging through the Android source code, I found that every IME contains an implementation of AbstractInputMethodService. Android provides a standard implementation (android.inputmethodservice.InputMethodService) which if you look at, has a public setExtractView method, and an onCreateExtractTextView method, which inflates com.android.internal.R.layout.input_method_extract_view.xml, which in turn contains com.android.internal.R.id.inputExtractEditText! So a hacky solution would be to hope that most of your customer's IMEs' InputMethodServices use this same XML (which as far as I can tell, has been in Android for a while), and you can attempt to grab a reference to this EditText by it's ID and change it's typeface. Unfortunately I'm not sure offhand where in the view hierarchy/window the views of an InputMethodService are added, and if they're accessible from your app/activitys process.
Source for InputMethodService:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/inputmethodservice/InputMethodService.java
Source for the layout XML:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/input_method_extract_view.xml
If you really want to get yourself in trouble, perhaps there's a way to get a reference to the IME service itself, and use reflection to alter the extracted view. The standard InputMethodService holds a package-private reference to mExtractEditText :)
I know not the answer you're looking for but perhaps it'll put you in the right direction...or some direction at least.
If you have a single editable element on your Dialog, how about handling orientation changes and
in case of Portrait orientation, show the Dialog
in case of Landscape orientation, show a fullscreen Fragment with the EditText and Buttons (as others have stated; disable fullscreen editing mode for the EditText), request focus for the EditText, show Keyboard.
in case of orientation switching dismiss Dialog / show Fragment with the already entered text (and vice versa)
This might be conceptually good because if the user wishes to enter text, he/she will always end up in a fullscreen editing layout in Landscape orientation. And since there is only one editable view in the original Dialog, you don't explicitly need the Dialog to select anything else to edit (another EditText for example).

Categories

Resources