Automatic popping up keyboard on start Activity - android

I got a relative simple question. I have an activity with a lot of EditText's in them. When I open the activity it automatically focusses to the first EditText and displays the virtual keyboard.
How can I prevent this?

Use this attributes in your layout tag in XML file:
android:focusable="true"
android:focusableInTouchMode="true"
As reported by other members in comments it doesn't works on ScrollView therefore you need to add these attributes to the main child of ScrollView.

You can add this to your Android Manifest activity:
android:windowSoftInputMode="stateHidden|adjustResize"

I have several implementations described here, but now i have added into the AndroidManifest.xml for my Activity the property:
android:windowSoftInputMode="stateAlwaysHidden"
I think this is the easy way even if you are using fragments.
"stateAlwaysHidden" The soft keyboard is always hidden when the
activity's main window has input focus.

If you have another view on your activity like a ListView, you can also do:
ListView.requestFocus();
in your onResume() to grab focus from the editText.
I know this question has been answered but just providing an alternative solution that worked for me :)

Use this in your Activity's code:
#Override
public void onCreate(Bundle savedInstanceState) {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

https://stackoverflow.com/a/11627976/5217837 This is almost correct:
#Override
public void onCreate(Bundle savedInstanceState) {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
But it should be SOFT_INPUT_STATE_HIDDEN rather than SOFT_INPUT_STATE_ALWAYS_VISIBLE

I had a simular problem, even when switching tabs the keyboard popped up automatically and stayed up, with Android 3.2.1 on a Tablet. Use the following method:
public void setEditTextFocus(EditText searchEditText, boolean isFocused)
{
searchEditText.setCursorVisible(isFocused);
searchEditText.setFocusable(isFocused);
searchEditText.setFocusableInTouchMode(isFocused);
if (isFocused) {
searchEditText.requestFocus();
} else {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(searchEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS );
}
}
In the onCreate() and in the onPause() of the activity for each EditText:
setEditTextFocus(myEditText, false);
For each EditText an OnTouchListener:
myEditText.setOnTouchListener(new EditText.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
setEditTextFocus(myEditText, true);
return false;
}
});
For each EditText in the OnEditorActionListener:
myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
.......
setEditTextFocus(myEditText, false);
return false;
}
});
And for each EditText in the layout xml:
android:imeOptions="actionDone"
android:inputType="numberDecimal|numberSigned" // Or something else
There is probably more code optimizing possible.

((InputMethodManager)getActivity().getSystemService("input_method")).hideSoftInputFromWindow(this.edittxt.getWindowToken(), 0);

I have found this simple solution that worked for me.Set these attributes in your parent layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
And now, when the activity starts this main layout will get focus by default.
Also, we can remove focus from child views at runtime by giving the focus to the main layout again, like this:
findViewById(R.id.mainLayout).requestFocus();
Hope it will work for you .

this is the solution I am using, is not the best solution but it's working well for me
editComment.setFocusableInTouchMode(false);
editComment.setOnTouchListener(new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event)
{
// TODO Auto-generated method stub
editComment.setFocusableInTouchMode(true);
editComment.requestFocus() ;
return false;
}});

Interestingly, this documentation https://developer.android.com/training/keyboard-input/visibility.html states that when an activity starts and focus is given to a text field, the soft keyboard is not shown (and then goes on to show you how to have the keyboard shown if you want to with some code).
On my Samsung Galaxy S5, this is how my app (with no manifest entry or specific code) works -- no soft keyboard. However on a Lollipop AVD, a soft keyboard is shown -- contravening the doc given above.
If you get this behavior when testing in an AVD, you might want to test on a real device to see what happens.

This has some good answers at the following post : Stop EditText from gaining focus at Activity startup. The one I regularly use is the following code by Morgan :
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="#+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="#id/autotext"
android:nextFocusLeft="#id/autotext"/>
NOTE : The dummy item has to be PLACED RIGHT BEFORE the focusable element.
And I think it should work perfectly even with ScrollView and haven't had any problems with accessibility either for this.

This occurs when your EditText automatically gets Focus as when you activity starts. So one easy and stable way to fix this, is simply to set the initial focus to any other view, such as a Button etc.
You can do this in your layout XML, no code required..

Accepted answer is not working for me, that's why give answer working solution, may be it is helpful !
EditText edt = (EditText) findViewById(R.id.edt);
edt.requestFocus();
edt.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
edt.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
Now keyboard is open enjoy :)

android:windowSoftInputMode="stateHidden|adjustResize"
Working fine

Add below code to your top of the activity XML and make sure the View is above EditText
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusableInTouchMode="true"/>

android:focusableInTouchMode="true"
Add the above line to xml of EditText or TextInputLayout which has focus and is causing the softInputKeyboard to pop up.
This solved the problem for us and now the keyboard doesn't popup

search_edit_text = (EditText) findViewById(R.id.search_edit_text);
search_edit_text.requestFocus();
search_edit_text.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
search_edit_text.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
This works for me guys fragment may have some different syntax . THIS WORKS FOR ACTIVITY

Use this in your Activity's code:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

If your view has EditText and Listview then Keyboard will open up by default.
To hide keyboard from popping up by default do the following
this.listView.requestFocus();
Make sure you are requesting focus on listview after getting view for editText.
For e.g.
this.listView = (ListView) this.findViewById(R.id.list);
this.editTextSearch = (EditText) this.findViewById(R.id.editTextSearch);
this.listView.requestFocus();
If you do it, then editText will get focus and keyboard will pop up.

Related

onFocusChange is not working for me

I want to disappear the keyboard when the focus goes out of the TextEdit box. I have throughly searched stackoverflow and google for an answer and have tried every single response/article I have seen but nothing seems to work for me.
As many, I am very new to Android development. I must be overlooking some minor detail to no avail.
My current implementation (again, I have tried many solutions) is as follows:
My class implements OnFocusChangeListener. OnCreate after calling super and setContentView I do:
EditText editText = (EditText) findViewById(R.id.text_box);<br> editText.setOnFocusChangeListener(this);
and
#Override
public void onFocusChange(View v, boolean hasFocus) { Log.d(TAG, "--> onFocusChange"); }
But I never see that Log message.
Sometimes I think that onFocusChange is not what I think it is. My idea is that when we touch the textedit field this view gets the focus, and when you touch any other area of the screen, say a button/listbox/etc the textedit losses the focus and onFocusChange should be called, but it is not, I never see the log entry.
Perhaps it is useful to clarify that I am using Android Studio and created an app that uses fragments.
So, I am doing this on the Detail Activity which in turn is part of a fragment. I have also tried to do it on the onActivityCreated of the fragment.
Neither approach works for me.
Any ideas what I can be missing here?
I would really appreciate your comments.
edittext.requestFocus();
or
Try this :
EditText editText = (EditText) findViewById(R.id.text_box);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus == true){
edittext.requestFocus();
}
else{
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
}
});
editText.setFocusableInTouchMode(true);
try doing that first?
You need to have the field be focusable before you can have the Focus Events fire on it. But i guess it didn't help you in this case :(
onFocusChangeListener is an interface which when you try to implement it as you did you also need to pass the context you wanna be Observed, so in practice one of the view elements of your ViewHolder must be Observed. so you can do it like:
(Assuming that you want to check when your EditText got focused)
editText.onFocusChangeListener = this
even if you are in an Adapter or ViewHolder while you are implementing OnFocusChangeListener you can assign that corresponding class to that Context you wanna be supervised in case of focus changes.

Empty space when I return to Activity (Soft Keyboard forced)

I have an ActionView with menu item on ActionBar (using ActionBarSherlock), I'm able to display an EditText as a search field in it. It's an input to launch another Activity with a CustomView in ActionBar which it displays the same layout (I don't use anything to force the SoftKeyboard to appear in this second activity, there is no problem here). When I want to make the Soft Keyboard appears/disapears automatically when the view collapse in first activity, I use:
openKeyboard method
mImm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
closeKeyboard method
mImm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
I use the ActionExpandListener to make the SoftKeyboard appears or disappears when the View expands or collapse. With these two methods above, I have the expected result. I found this on several questions on SO (especially on Close/hide the Android Soft Keyboard and Showing the soft keyboard for SearchView on ActionBar or Forcing the Soft Keyboard open).
Just to understand, when I used SHOW_IMPLICIT or SHOW_FORCED alone, it was no effect on lower versions (as 2.+). The EditText was focused but the keyboard didn't show up (so, you guess it was a bad thing). In recent versions (as 4.+ for example), it was a nice effect and no problem. Then, I forced keyboard to show up with the openKeyboard method above.
Now, I got some troubles with this...
On lower versions, I got "empty" space before and after the keyboard created/destroyed, I can live with this. BUT in recent versions, I got "empty" space which it displays when I return to the first Activity. And it's here during less than one second, but sufficient to see that!
To better understand what happens, see the image below:
1. Second Activity: I press the Up Home Button - the keyboard disappears properly.
2. (back to) First Activity: my ListView is covered by a "empty" space (background color in my application). And it disappears (this is the same height of the SoftKeyboard, no possible doubt!)
I guess it's because I forced the keyboard to appear in my first activity although I also forced the keyboard to hide when I go the second, but how can I resolve the "empty" space when I return to the first activity?
Summary
1) A activity => press item in menu > view collapse > show the keyboard > tap text > send it > hide keyboard > launch B activity.
2) B activity => setCustomView in actionbar > show the keyboard only if the edittext is focused/clicked > tap text > send it > hide keyboard > refresh content > press home button > return to A activity
3) A activity => "empty" screen > screen disappears.
Any help will be very appreciate.
Thanks for your time.
EDIT
I add my code of my first class, to see if someone tells me what I'm doing wrong. Maybe it's my code which makes the issue.
Menu (ActionView)
ActionBar actionBar;
MenuItem itemSearchAction;
EditText mSearchEdit;
InputMethodManager mImm;
#Override
public boolean onCreateOptionsMenu(final Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
itemSearchAction = menu.findItem(R.id.action_search);
View v = (View) itemSearchAction.getActionView();
mSearchEdit = (EditText) v.findViewById(R.id.SearchEdit);
itemSearchAction.setOnActionExpandListener(this);
return true;
}
OnActionExpandListener
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
actionBar.setIcon(R.drawable.ic_app_search); // change icon
mSearchEdit.requestFocus(); // set focus on edittext
openKeyboard(); // the method above
mSearchEdit.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
closeKeyboard(); // same method as above
// new Intent() to second activity
// perform with startActivity();
itemSearchAction.collapseActionView(); // collapse view
return true;
}
return false;
}
});
// add a clicklistener to re-open the keyboard on lower versions
mSearchEdit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openKeyboard();
}
});
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
actionBar.setIcon(R.drawable.ic_app_logo); // change icon again
if(!(mSearchEdit.getText().toString().equals("")))
mSearchEdit.setText(""); // reinitial the edittext
return true;
}
OnOptionsItemSelected
// I had this verification when I make new Intent() to
// a new activity, just in case (works like a charm)
if(itemSearchAction.isActionViewExpanded())
itemSearchAction.collapseActionView();
ActionView (Item + layout)
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_app_search"
android:title="#string/action_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionLayout="#layout/search_actionview" />
<EditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SearchEdit"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="right|bottom" android:gravity="left"
android:layout_marginBottom="6dip"
android:hint="#string/action_search"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:singleLine="true"
android:cursorVisible="true"
android:inputType="text"
android:imeOptions="actionSearch|flagNoExtractUi"
android:imeActionLabel="#string/action_search"
android:focusable="true" android:focusableInTouchMode="true"
android:background="#drawable/bt_edit_searchview_focused" >
<requestFocus />
</EditText>
UPDATE
I see a lot of similar issues, with EditText in ActionBar which not makes the keyboard appear even the focus has set. I tried this again (even if I already tested several time):
/*
* NOT WORKING
* Sources: https://stackoverflow.com/questions/11011091/how-can-i-focus-on-a-collapsible-action-view-edittext-item-in-the-action-bar-wh
* https://stackoverflow.com/a/12903527/2668136
*/
int mode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
getWindow().setSoftInputMode(mode);
postDelayed() to show: .showSoftInput(mSearchEdit, InputMethodManager.SHOW_IMPLICIT); - 200ms (Not working on lower versions)
postDelayed() to hide: .hideSoftInputFromWindow(mSearchEdit.getWindowToken(), 0); - 200ms
new Runnable() on edittext => requestFocus() + showSoftInput(SHOW_IMPLICIT/FORCED/HIDE_NOT_ALWAYS/HIDE_IMPLICIT_ONLY)
It seems with me, only SHOW_FORCED|HIDE_IMPLICIT_ONLY can force the keyboard to show automatically when the view collapse. After this, in all versions, I must to make a hideSoftInputFromWindow to 0 for hiding it.
BUT this undisplays the keyboard even if the edittext is pressed, so I added an ClickListener to force the keyboard to show again (this happens only on lower versions).
UPDATE2:
It's clearly weird, when I try to make a little Thread like I saw in many SO answers (with/without ABS), nothing happens in lower versions.
I tried a different way. I created the new thread to have a short time before call the new intent for hide the keyboard. I had the keyboard which forced to close, OK. And then I opened the new activity, OK. But now when I return, it's worth! The "empty" space is also on lower versions when I come back. I did this:
// close the keyboard before intent
closeKeyboard();
// make the intent after 500 ms
Handler handler = new Handler();
Runnable runner = new Runnable() {
public void run() {
// new intent with startActivity()
}
};
handler.postDelayed(runner, 500);
// collapse the View
itemSearchAction.collapseActionView();
It gives me headaches! I don't understand why in my case, the tip above not working whereas on other answers, when they use a new thread to show/hide the keyboard, this works perfectly.
NOTE: my tests were on (emulator:) GalaxyNexus, NexusS, NexusOne and (real devices:) Samsung GalaxySL (2.3.6) and Nexus4 (4.4).
If someone can help me with this ugly situation. Thanks in advance.
Did you tried this one?
setContentView(R.layout.activity_direction_3);
getWindow().getDecorView().setBackgroundColor(
android.R.color.transparent);
Remove Translucent theme:
android:theme="#style/Theme.AppCompat.Translucent"
and use your Activity in manifest.xml as:
<activity
android:name=".SearchActivity"
android:screenOrientation="portrait">
I had the same issue.
Try to add in Manifest, in First Activity:
android:windowSoftInputMode="adjustPan"
I have found the solution here:
Soft Keyboard pushes layout of my activity out of screen

Force FullScreen on EditText in Android

I am currently developing an app with Samsung Galaxy Tab 2 as my device.
My Code in the XML is:
<EditText
android:id="#+id/analysis_text"
style="#style/icon_text"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:onClick="onBtnClicked"
/>
When this code executes, the full screen data entry mode (Extract Mode) is triggered automatically only in certain situations.
I would like my users to get a full data entry screen while editing text in this control, regardless of the screen or positioning of the control.
Another rephrase of this question:
How do I force full screen data entry mode for EditText boxes in my activity no matter what the content is?
I solved this issue, not really solved, but found a valid work-around.
The workaround is that I designed a text editor (which looks similar to the fullscreen UI) and on click of each of those EditBoxes the new UI activity is triggerred (with the startActivityForResult() so that once they are completed control is handed back to the calling activity) and after completion of edit the text is transferred back into the main screen.
I also ensured that those boxes which transfer the control do not take focus so that they immediately transfer control to the new UI.
This way I have been able to implement a cancel button, which now actually allows the user to go back without saving the changes he accidentally makes.
I am open to new ideas, but this has worked for me.
Code in Activity:
public void onBtnClicked(View v) {
EditText current_text_box = (EditText) v;
Intent intent = new Intent(ObservationActivity.this,
TexteditorActivity.class);
intent.putExtra("start_text", current_text_box.getText().toString());
intent.putExtra("start_position", current_text_box.getSelectionStart());
startActivityForResult(intent, v.getId());
}
Code in XML:
<EditText
android:id="#+id/observation_text"
style="#style/icon_text"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:onClick="onBtnClicked" >
</EditText>
To create the full screen UI I used code, you can use any like (http://android-richtexteditor.googlecode.com/)
You Can Try This
yourEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
yourEditText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
}
});
Import LayoutParams of your Parent Layout. Your answer will also work well.

Way to hide softkeypad provided not effecting the features of the edittext in android

I have hidden soft keypad because I have custom keypad on the app. When the edittext is clicked, soft keypad shouldn't pop up. So, I have tried so many ways from the sources, but nothing worked except the editText.setFocusable(false); . But now the problem is edittext is not getting highlighted when I clicked it and even cursor is not visible. I have tried using InputManager, android:windowSoftInputMode="stateAlwaysHidden in the manifest and referred many like link 1 , link 2 etc., but these techniques atleast don't even hide the soft keypad on my app. Finally I got this through setFocusable, but there is a highlighting problem and cursor invisible problem and even requestFocus() in the onClickListener didn't work. Can someone give exact solution for this problem? Code snippet is appreciated.
Try this one in activity class
getwindow().setsoftInputMode(winowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
This one is avoiding of soft key pad
please use this in manifest:
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden"
You ddont need to add any method in menifist. just add this code.. It will automaticlly hide when you click on button to get value.
Want to hide softkeyboard use this code in your click listener method.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFomWindow(edittext.getWindowToken(),0);
i hope this code work fine.
Try this:
InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFomWindow( edittext.getWindowToken(), 0);
how about if you editText.setOnTouchListener and when you create the new OnTouchListener do nothing something like:
editText.setOnTouchListener(new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});

EditText automatically opens soft keyboard when Fragment is visible with ViewPager

I have a Fragment (the compatibility version) with an EditText in its layout. I'm using a ViewFlipper to flip between fragments. When I get to this particular Fragment, the soft keyboard opens up automatically. This is not what I want. Here is what I've tried to stop it or hide it.
Tried:
android:descendantFocusability="beforeDescendants"
on the fragment's main view
Tried:
android:windowSoftInputMode="stateHidden"
and
android:windowSoftInputMode="stateAlwaysHidden"
in the manifest for the activity
Tried:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mViewPager.getChildAt(position).getWindowToken(), 0);
on the OnPageChangeListener of my ViewPager
Tried:
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(voucherView.findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);
in onCreateView in my Fragment
Tried:
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);
in onStart in my Fragment
Tried:
voucherView.findViewById(R.id.redeem_mobile_number).clearFocus();
in onCreateView in my Fragment
It seems to me like onPageChangeListener is the place to do this because the other calls happen before the soft keyboard is actually open. Any help would be great.
This post has a solution to the problem.
The answer was to add android:focusableInTouchMode="true" to the LinearLayout containing the EditText. Now it doesn't bring up the soft keyboard automatically.
<LinearLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:id="#+id/retailer_search_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Just follow it . And EditText should be within a LinearLayout.
Have you tried this?
<activity
android:name=".YourActivityName"
android:configChanges="keyboardHidden|orientation"
android:windowSoftInputMode="stateHidden" />
EDIT:
try this (I now it is a bad one but give a try to this) :)
Thread splashTread = new Thread() {
#Override
public void run() {
try {
sleep(1);
} catch (InterruptedException e) {
// do nothing
} finally {
runOnUiThread(new Runnable() {
public void run() {
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(youreditText.getWindowToken(), 0);
}
});
}
}
};
splashTread.start();
I had a soft keyboard disturbingly popup and pushing all views up when I click on an edit text in a fragment view (my app is a app of nested fragments - fragment in fragment)
I tried a dozen solutions here and on the internet, but nothing helped except this, which is edit the EditText itself in XML (not the view above/not the manifest/not overwride on create activities/not any other)
by adding android:focusableInTouchMode="false" line to your EditText's xml.
I borrowed the solution from ACengiz on this thread
how to block virtual keyboard while clicking on edittext in android?
Only 2 people voted for him? although for me it was a saver after hours of a headache
Add this to your activity tag in AndroidManifest.xml
keyboardHidden: will not let it open soft input keyboard automatically.
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize|stateHidden"
This worked for me.
edittext.setInputType(InputType.TYPE_NULL);
if (android.os.Build.VERSION.SDK_INT >= 11)
{
edittext.setRawInputType(InputType.TYPE_CLASS_TEXT);
edittext.setTextIsSelectable(true);
}
Try This
exitText.setFocusableInTouchMode(true);

Categories

Resources