I have an EditText and a custom keyboard, so i want to avoid softkeyboard to popping up. It must never pop up, but i need also to leave EditText focusable to use cursor. Simple as it is but so hard to accomplish.
I already tried a lot of solutions but they aren't working and since they are outdated i'm asking now for an actual working way. Solutions targetted as API 11 are such useless now since they don't work, already tried. I'd love to listen for suggestions from people who already tried the method on recent versions, such as Lollipop (API 21-22) or Marshmallow (23). I can't believe that there is no workaround, and i'm getting mad
This will help you
editText.setInputType(InputType.TYPE_NULL);
In your layout file add these line
android:descendantFocusability="beforeDescendants" and
android:focusableInTouchMode="true"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</EditText>
</RelativeLayout>
In your Activity class add this line
this.getWindow().
setSoftInputMode
(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Related
I have an Edit Text in one of my App layouts, and I want this EditText to only open the keyboard (I believe this is called being focused on?) when it is actually touched.
As of now, the keyboard opens with the EditText whenever the app opens, which isn't what I want.
I have tried many different XML tags to fix this:
android:focusable="false" <--- Prevents keyboard from opening at all.
android:focusable="true"
android:focusableInTouchMode = "true" <--- These tags give me the same result as no tags (keybaord will open on activity start)
android:focusedByDefault = "true" <--- Only available in API >= 23
What I am asking is, why is it so hard to disable default focus on an EditText? Surely I am missing an easy way to do this.
EDIT: Adding this line to my AndroidManifest fixed the issue:
android:windowSoftInputMode="stateHidden"
However, I don't like this solution. It seems like since this is in the Manifest, it will affect more UI elements than the single EditText I need to change.
Alternatively you can set the focus to the root layout element:
android:focusable="true"
android:focusableInTouchMode="true"
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true">
<EditText
android:inputType="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Use android:windowSoftInputMode="stateHidden"
If you dig deep into the Theme you are using for your Activity, you will find that the default value of windowSoftInputMode is stateUnspecified|adjustPan. And from the documentation:
stateUnspecified: Not specified, use what the system thinks is best. This is the default.
So depending on the the android device you run, your results will vary. I tried reproducing your case in API-26 emulator and the keyboard doesn't show up.You can use stateHidden to ensure that when an activity starts, the soft keyboard doesn't show up when the EditText gets focused on itself.
The other way to solve this is to requestFocus to some other element in the UI, making sure the EditText is not the first UI element to get focused. In my experience this is kind of a hack and it messes up the accessibility. The safest and clean way to accomplish is actually to use stateHidden.
stateHidden: Make the soft input area hidden when normally appropriate (when the user is navigating forward to your window).
Note that this will not affect any other UI elements. You can use adjustPan also to this, based on the screen background.
I seem to have quite a specific problem. I have two tablets, one runs on Android 6.0.1, the other on 5.1.1.
I have an activity and a fragment (the fragment is located on an activity). Each has an EditText element with the following layout:
<EditText
android:id="#+id/etInputForm_1_1"
android:layout_width="250dp"
android:layout_height="30dp"
android:layout_below="#id/tvDescription_1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:cursorVisible="true"
android:imeOptions="actionNext"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:textColor="#color/Black"
android:textSize="15sp"/>
The problem is, if I test it on the device with Android 6.0.1, everything seems to be ok, I can input text wherever I want to, however on the device with 5.1.1, the EditText in the fragment always seems to be empty no matter how many letters I type (the EditText in the activity still works fine).
But the logs still show that the text IS there (however we can't see it).
Anyone had similar problem and a solution to this?
I had a similar issue where the edit text hint wouldn't go away (representing text was in the field) and no text would show up when I was typing but my logs showed text was indeed in the field. I also had an issue where my spinners would not show the selected option
I solved it by enabling hardware acceleration for my application. Since it is enabled by default (I believe) I removed this line from my <application></application> section of my manifest file: android:hardwareAccelerated="false"
My issue resolved after removing following line from edit text.
android:textAllCaps="true"
The problem was resolved by using android.app.Fragment instead of android.support.v4.app.Fragment. Seems that the support fragment class is buggy when using on tablets with Android 5.1.1.
I'm not looking for code, either I won't post any, just an explanation, because I'm kind of lost.
There is this main issue about the resizing when softkeyboard appear.
In my case
I have a listView feeded with 2 editText and many textView with database content using a custom cursorAdapter.
1) AdjustPan
It's pretty simple. When I use the adjustPan property, everything works quite good, except the fact that when I press an editText in my listView and if the listview is bigger than the screensize, I can't scroll. This is actually the normal behaviour and I can understand it.
2) AdjustResize
Here I can scroll as much as I wish.
This property is the one I want to use. But I'm facing 2 issues :
When I press on one of the two editText, I just can't write in. Impossible, even thought it has the focus. I'm forcing the softkeyboard to appear, I try to type some letters in (remember that this editText is focused) but nothing happens.
Again, when I press one of the two editText, it just reorganize (apparently randomly) listview's items. Even thought it's working perfectly with adjustPan, with adjustResize, it's messing with items of the listView.
Any information about one of the 2 issues would be helpful. You can even ask for code, but one more time, I'm just looking for a general explanation that could help. Thanks.
Here this mention issue is same facing me in my app and here some change in my code is this working fine in my app. please try this...
<activity android:name="com.MainActivity"
android:configChanges="orientation|screenSize"/>
<ListView
android:id="#+id/fields_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
/>
<EditText
android:id="#+id/input_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:gravity="top"
android:inputType="none"
android:textColor="#color/black"/>
I am trying to disable autosuggest on this EditText, but all the methods outlined don't work with the Japanese IME keyboard and Swype. Is there a way to make it work correctly?
So far, I've tried everything in all kinds of combinations to no avail. Although all solutions work perfectly fine with the default keyboard, users report they still get autosuggest. This is a word game that needs word starting with certain letters, so I really need it.
<EditText
android:id="#+id/txtWord"
android:background="#drawable/textbox_bg"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right|center_vertical"
android:layout_weight="1"
android:singleLine="true"
android:inputType="textFilter|textNoSuggestions|textVisiblePassword"
android:imeOptions="actionNone"
>
<requestFocus />
</EditText>
Everything supplied to attributes like android:inputType are suggestions to the IME, not commands. Some IMEs will honor them, some will not. Hence, you are going to need to design your game such that either you do not care about the suggestions or you do not use an EditText widget.
InputType.TYPE_NULL or 'none' (check the System level attributes for specifics) should work in most cases, but as Mr Murphy says, they're just hints, so may not work (and presumably you can't OR is it anything else).
You can use this :
android:inputType="textNoSuggestions"
android:privateImeOptions="nm"
The first time i focus an edittext view i notice a lag of one or two seconds before i can write anything in the textbox.
I notice this behavior even on an app without any code more than what's nessecary to initialize the application.
What am i doing wrong?
I've INSTANTLY fixed this issue for me; I saw in the DDMS that a lot of redraw's and recalculations were occurring while entering text, and a lot of info about RelativeLayouts were being called. So, I checked my layout; i had some Multi-Line EditText's who were direct children of a RelativeLayout. So, I wrapped those up into a Linear Layout, and specified my desired width/height at the LinearLayout, not each EditText.
Guess what? It totally fixed it!!
(below, some code... keep in mind, this is just an approximation. Don't try and copy/paste)
BEFORE:
<RelativeLayout>
<EditText
android:layout_width="wrap_content" />
<EditText
android:layout_width="wrap_content" />
</RelativeLayout>
AFTER:
<RelativeLayout>
<LinearLayout
android:layout_width="wrap_content" >
<EditText
android:layout_width="fill_parent" />
<EditText
android:layout_width="fill_parent" />
</LinearLayout>
</RelativeLayout>
Wrapped my EditText's into a LinearLayout, and relinquished dynamic layout controls to the LinearLayout.
It was an amazing and instant improvement.
Are you using the emulator?
This is common when you are using the emulator regardless of debug mode or not...at least from my (limited) experience so far. Try your app out on a real phone and see what happens.
I turned off USB debugging and uninstalled a few keyboards. Seems to work fine now. Thanks all.
Edit AndroidManifest:
My old code
< uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
My new code
< uses-sdk android:minSdkVersion="8" />
I just removed the targetSdkVersion and the lag went away.
In my case the symptoms were the same, a delay occurred to present the keyboard and when typing the letters were gradually appearing.
The solution is because I had put a Background image in the RelativeLayout, when I did a test taking the background worked out and stopped the delay, so I entered an online site that reduces photos and then reduced from 93kb to 50kb and worked perfectly.
In my case the problem was the background-drawable for the activity (as dialog) on XML, it was too heavy. changing it, works fine.
In my case, the lag was because of the heavy serialised objects I used to pass in Intent putExtra() of activities in the app. Those would continue to stay in the memory and cause the problem.