EditText with attribute singline="true" doesn't moves up when keyboard appears - android

Reproduced on Nexus 7 android 4.3
Workflow:
Set focus to edit text first time - keyboard appears, EditText is
visible;
Hide Keyboard;
Set focdus to edit text second time - keyboard appears, EditText
doesn't moving up.
(EditText aligned on the bottom of the screen)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/edit_text"
android:layout_gravity="bottom"
android:gravity="center"
android:singleLine="true"
android:imeOptions="actionSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I tried this: android:windowSoftInputMode="adjustPan" or adjustPan|adjustResize , but now effect.
Anyone knows how to resolve this issue?
Updates:
I figured out : the problem is in attribute android:singline="true"; This attribute needed to show search button, and start search after it was cliked on keyboard - otherwise shown enter button after clicking wich we going to the next line.
Q: Does Your activity using FLAG_FULLSCREEN ?
A: Yes. But without this flag still reproduced.

android:windowSoftInputMode="adjustResize"

Try like this..
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

in your manifest file under activity tag just add:
android:windowSoftInputMode="adjustpan"
will solve your problem!!

you can't specify textfield with type actionSearch as a single line textfield.try removing it.

try this in your manifest file, add to your activity
**
android:windowSoftInputMode="stateVisible|adjustPan"
**

Related

Android - AdjustResize won't work with external library that extends FrameLayout

I use an external library called DragListView here. This DragListView extends a FrameLayout and it contains a RecyclerView inside. The structure is like:
DragListView extends FrameLayout {
RecyclerView mRecyclerView;
}
The items populated into RecyclerView contains an EditText. With the EditText near the top of the screen (which is not covered if the soft keyboard appears) works just fine. But the one which is covered by the soft keyboard will gain focus then lose focus at once when called myEditText.requestFocus(); then the keyboard covers that EditText.
Here is the layout of my activity.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.ui.activities.ChecklistsActivity">
<include layout="#layout/custom_action_bar"
android:id="#+id/action_bar"/>
<com.woxthebox.draglistview.DragListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:id="#+id/recycler_view_checklists"
/>
</LinearLayout>
android:layout_gravity="top" works for me once with my old structure where the DragListView is a nested child inside a RecyclerView (I set the top gravity for the RecyclerView), but it's not working anymore in this case.
I cannot use AdjustPan because it will push my action bar away (but it works, sadly). Mine app is not in fullscreen (still able to see the status bar, I assume it's not fullscreen, correct me if I'm wrong please). I tried a few things but nothing work.
I called myEditText.setFocusable(true); and myEditText.setFocusableInTouchMode(true); just before myEditText.requestFocus();.
I put android:descendantFocusability="afterDescendants" for the DragListView or the root LinearLayout.
I tried different ways of calling the keyboard to popup like
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
or with a KeyboardUtils which received the Activity for getCurrentFocus();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
And one more thing just in case. I don't know if there's anything related to my "custom" keyboard with edtSubItemName.setImeActionLabel("Done", KeyEvent.KEYCODE_ENTER); because I want a multiline EditText with "Done" action key. The xml of the EditText item is here:
<EditText
android:id="#+id/edit_text_sub_checklist_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/height_checklist_setting"
android:layout_marginRight="#dimen/height_checklist_setting"
android:inputType="text"
android:imeOptions="actionDone"
android:maxLength="256"
android:textSize="#dimen/text_size_default"
android:visibility="invisible" />
The android:visibility="invisible" is because there's a button to press to make it visible.
I'm getting mad with it for a few days. Was I missing something? Feel free to ask for more information.
Thank you all for your valuable time.
I solved it by setting layoutManager.setStackFromEnd(true); for the layout manager before setting myDragListView.setLayoutManager(layoutManager);
The list then start at the last item, so I just call myDragListView.scrollToPosition(0); after setAdapter to make it back to the top like normal. The interesting thing is that the position of the items is still the same (still from top to bottom) so there's nothing much to do.
Hope this helps someone.

Force keyboard to show on a screen

I need the soft keyboard to be shown on a screen whithout an EditText - just a keyboard.
I have an idea about a game which would be controlled by a soft keyboard, but what I've found on stackoverflow - doesn't work as it should.
here's my game.xml - it's a layout to main Activity of this app :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GameActivity" >
<com.vladdrummer.textmaster.Game
android:id="#+id/game"
android:layout_width="wrap_content"
android:windowSoftInputMode="adjustResize"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
here's how it's called in Activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);//this suppose to force keyboard to be on screen
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);//чтоб экран не гас
setContentView(R.layout.game);
this works only in portrait/vertical orientation and don't work in landscape/horizontal.
(In case, my Game class is extending View class and I'm working with canvas)
But I need this to be shown in horizontal mode.
there were another way to keep keyboard onscreen :
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
but that doesn't do a thing
so,please, I need a soft keyboard to be sticked on a screen, in landscape mode
Try execute the following code in a seperate theread.
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(im != null) im.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);

How to hide keyboard in a edittext + listview layout

I have a LinearLayout composed by a ListView(which loads from an AsynTask) and an EditText(so I can filter that list). Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Filtrar por nombre..." >
</EditText>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
The problem is that when the activity starts, the keyboard is shown up and I only want to show it when the EditText is clicked for a search.
I've tried several methods such as writing the following in the manifest
android:windowSoftInputMode="stateHidden"
and including this in the class
InputMethodManager iMM = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
iMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
The only thing I've achieved is to not show the keyboard but not showing the loaded stuff of the list(just the EditText and the rest of the screen plain black), and once I click on the EditText, they appear both keyboard and the stuff of the listView.
Any posible solution for this?
EDIT:
I've tried the following solutions(thanks to #Sush, #boztalay and #Agata Sworowska), but none did the trick.
-Placed in my layout:
android:focusable="true"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
-And placed in my onCreate() method:
ListView listView = findViewById(R.id.list);
listView.setFocusableInTouchMode(true);
listView.requestFocus();
Any other posibility?
NEW EDIT:
I've noticed that when it doesn´t focus on the EditText, the listView doesn´t load until I focus back the EditText, llike if it was waiting for it. I've tried to set up the EditText after the code that loads the ListView but the problem persists.
This sounds like an issue with focus. What's happening is when the app is started, the EditText gets focus, and the keyboard pops up. You should try to make it so that the ListView gets focus. This way, the keyboard won't pop up until the user gives the EditText focus when they click on it.
In your Java, you should get an instance of the ListView, then call a couple of functions:
ListView listView = findViewById(R.id.list);
listView.setFocusableInTouchMode(true);
listView.requestFocus();
If you put that in your onCreate(), focus will be given to the ListView, and they keyboard won't come up until the user clicks the EditText.
See this SO question for more details.
You can just add below two attributes to your LinearLayout.
android:focusable="true"
android:focusableInTouchMode="true"
Try adding in Your layout, that contains EditText this:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
I hope it helps.
http://www.mysamplecode.com/2012/02/android-edittext-hide-soft-keyboard.html
This is a solution I found for the issue here. Do not understand why listivew should do this, but the workaround helps.

Android : clear focus on edittext when activity starts

I've some settings page in my app. Once the activity gets starts directly it focus to edittext and i used following code to clear foucs.
<RelativeLayout
android:id="#+id/RequestFocusLayout"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
and in java code
RelativeLayout focuslayout = (RelativeLayout) findViewById(R.id.RequestFocusLayout);
focuslayout.requestFocus();
The above code is working fine when activity starts at first time and if same activity starts again, automatically edittext get focus.
Can anyone help me to solve this issue.
Actually, the first focusable view in the activity receives initial focus. If that happens to be your EditText, it will be initially focused.
If you don't want that, here's your options:
Focus another view
Programmatically identify what view you do want to give initial focus to.
#Override
protected void onStart() {
super.onStart();
findViewById( R.id.yourOtherViewId ).requestFocus();
}
Make an earlier view in your layout focusable
If you rather it appears as though "no view has initial focus" you could make the parent view group focusable. In the following example, I make my LinearLayout focusable by setting android:focusableInTouchMode="true":
<LinearLayout
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
...
If Come back from other activity edittext get focused.
put these line onStart() or on onReusme()
RelativeLayout focuslayout = (RelativeLayout) findViewById(R.id.RequestFocusLayout);
focuslayout.requestFocus();
If your EditText is a child of your RelativeLayout you can use android:descendantFocusability to request the focus:
<RelativeLayout
android:id="#+id/RequestFocusLayout"
android:focusable="true"
android:layout_width="0px"
android:layout_height="0px"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" />
I used the solution shown up in this page but it didn't work. Add this attribute to your activity tag into AndroidManifest:
android:windowSoftInputMode="stateHidden"
It works perfectly.
Me realy help only android:focusableInTouchMode="true" in my parent view group.
Put the code to remove the focus in your onStart() method and it should work fine.
In the layout XML file, specify an imeOption on your EditText:
android:imeOptions="actionGo"
Next, add an action listener to your EditText in the Activity's java file
mYourEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// hide virtual keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mYourEditText.getWindowToken(), 0);
return true;
}
return false;
}
});
Where mYourEditText is an EditText object
If on starting the Activity it focuses on EditText on the screen.
use
android:focusableInTouchMode="true"
in the parent containing that EditText. Like if EditText is inside a RelativeLayout use this line in the RelativeLayout.

How to stop EditText from gaining focus when an activity starts in Android?

I have an Activity in Android, with two elements:
EditText
ListView
When my Activity starts, the EditText immediately has the input focus (flashing cursor). I don't want any control to have input focus at startup. I tried:
EditText.setSelected(false);
EditText.setFocusable(false);
No luck. How can I convince the EditText to not select itself when the Activity starts?
Adding the tags android:focusableInTouchMode="true" and android:focusable="true" to the parent layout (e.g. LinearLayout or ConstraintLayout) like in the following example, will fix the problem.
<!-- 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"/>
Is the actual problem that you just don't want it to have focus at all? Or you don't want it to show the virtual keyboard as a result of focusing on the EditText? I don't really see an issue with the EditText having a focus on the start, but it's definitely a problem to have the softInput window open when the user did not explicitly request to focus on the EditText (and open the keyboard as a result).
If it's the problem of the virtual keyboard, see the AndroidManifest.xml <activity> element documentation.
android:windowSoftInputMode="stateHidden" - always hide it when entering the activity.
or android:windowSoftInputMode="stateUnchanged" - don't change it (e.g. don't show it if it isn't already shown, but if it was open when entering the activity, leave it open).
A simpler solution exists. 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 focused by default.
Also, we can remove focus from child views at runtime (e.g., after finishing child editing) by giving the focus to the main layout again, like this:
findViewById(R.id.mainLayout).requestFocus();
Good comment from Guillaume Perrot:
android:descendantFocusability="beforeDescendants" seems to be the
default (integer value is 0). It works just by adding
android:focusableInTouchMode="true".
Really, we can see that the beforeDescendants is set as default in the ViewGroup.initViewGroup() method (Android 2.2.2). But not equal to 0. ViewGroup.FOCUS_BEFORE_DESCENDANTS = 0x20000;
Thanks to Guillaume.
The only solution I've found is:
Create a LinearLayout (I don't know if other kinds of Layout will work)
Set the attributes android:focusable="true" and android:focusableInTouchMode="true"
And the EditText won't get the focus after starting the activity
The problem seems to come from a property that I can only see in the XML form of the layout.
Make sure to remove this line at the end of the declaration within the EditText XML tags:
<requestFocus />
That should give something like that :
<EditText
android:id="#+id/emailField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress">
//<requestFocus /> /* <-- without this line */
</EditText>
using the information provided by other posters, I used the following solution:
in the layout XML
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:id="#+id/linearLayout_focus"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<!-- AUTOCOMPLETE -->
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:inputType="textNoSuggestions|textVisiblePassword"/>
in onCreate()
private AutoCompleteTextView mAutoCompleteTextView;
private LinearLayout mLinearLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
//get references to UI components
mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
mLinearLayout = (LinearLayout) findViewById(R.id.linearLayout_focus);
}
and finally, in onResume()
#Override
protected void onResume() {
super.onResume();
//do not give the editbox focus automatically when activity starts
mAutoCompleteTextView.clearFocus();
mLinearLayout.requestFocus();
}
Try clearFocus() instead of setSelected(false). Every view in Android has both focusability and selectability, and I think that you want to just clear the focus.
The following will stop EditText from taking focus when created but grab it when you touch them.
<EditText
android:id="#+id/et_bonus_custom"
android:focusable="false" />
So you set focusable to false in the xml, but the key is in the java, which you add the following listener:
etBonus.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}
});
Because you are returning false, i.e. not consuming the event, the focusing behavior will proceed like normal.
Late but simplest answer, just add this in the parent layout of the XML.
android:focusable="true"
android:focusableInTouchMode="true"
Upvote if it helped you! Happy Coding :)
I had tried several answers individually but the focus is still at the EditText. I only managed to solve it by using two of the below solution together.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
( Reference from Silver https://stackoverflow.com/a/8639921/15695 )
and remove
<requestFocus />
at EditText
( Reference from floydaddict https://stackoverflow.com/a/9681809 )
None of these solutions worked for me. The way I fix the autofocus was:
<activity android:name=".android.InviteFriendsActivity"
android:windowSoftInputMode="adjustPan">
<intent-filter >
</intent-filter>
</activity>
Simple solution:
In AndroidManifest in Activity tag use
android:windowSoftInputMode="stateAlwaysHidden"
You can just set "focusable" and "focusable in touch mode" to value true on the first TextView of the layout. In this way when the activity starts the TextView will be focused but, due to its nature, you will see nothing focused on the screen and, of course, there will be no keyboard displayed...
The following worked for me in Manifest. Write,
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
I needed to clearly focus on all fields programmatically. I just added the following two statements to my main layout definition.
myLayout.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
myLayout.setFocusableInTouchMode(true);
That's it. Fixed my problem instantly. Thanks, Silver, for pointing me in the right direction.
Add android:windowSoftInputMode="stateAlwaysHidden" in the activity tag of the Manifest.xml file.
Source
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 :)
Try this before your first editable field:
<TextView
android:id="#+id/dummyfocus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/foo"
/>
findViewById(R.id.dummyfocus).setFocusableInTouchMode(true);
findViewById(R.id.dummyfocus).requestFocus();
Add following in onCreate method:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Write this line in your Parent Layout...
android:focusableInTouchMode="true"
Being that I don't like to pollute the XML with something that is related to functionality, I created this method that "transparently" steals the focus from the first focusable view and then makes sure to remove itself when necessary!
public static View preventInitialFocus(final Activity activity)
{
final ViewGroup content = (ViewGroup)activity.findViewById(android.R.id.content);
final View root = content.getChildAt(0);
if (root == null) return null;
final View focusDummy = new View(activity);
final View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View view, boolean b)
{
view.setOnFocusChangeListener(null);
content.removeView(focusDummy);
}
};
focusDummy.setFocusable(true);
focusDummy.setFocusableInTouchMode(true);
content.addView(focusDummy, 0, new LinearLayout.LayoutParams(0, 0));
if (root instanceof ViewGroup)
{
final ViewGroup _root = (ViewGroup)root;
for (int i = 1, children = _root.getChildCount(); i < children; i++)
{
final View child = _root.getChildAt(i);
if (child.isFocusable() || child.isFocusableInTouchMode())
{
child.setOnFocusChangeListener(onFocusChangeListener);
break;
}
}
}
else if (root.isFocusable() || root.isFocusableInTouchMode())
root.setOnFocusChangeListener(onFocusChangeListener);
return focusDummy;
}
Late, but maybe helpful. Create a dummy EditText at the top of your layout then call myDummyEditText.requestFocus() in onCreate()
<EditText android:id="#+id/dummyEditTextFocus"
android:layout_width="0px"
android:layout_height="0px" />
That seems to behave as I expect. No need to handle configuration changes, etc. I needed this for an Activity with a lengthy TextView (instructions).
Yeah, I did the same thing - create a 'dummy' linear layout which gets the initial focus. Furthermore, I set the 'next' focus IDs so the user can't focus it anymore after scrolling once:
<LinearLayout 'dummy'>
<EditText et>
dummy.setNextFocusDownId(et.getId());
dummy.setNextFocusUpId(et.getId());
et.setNextFocusUpId(et.getId());
a lot of work just to get rid of focus on a view.
Thanks
For me, what worked on all devices is this:
<!-- fake first focusable view, to allow stealing the focus to itself when clearing the focus from others -->
<View
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
Just put this as a view before the problematic focused view, and that's it.
<TextView
android:id="#+id/textView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
style="#android:style/Widget.EditText"/>
This is the perfect and easiest solution. I always use this in my app.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
The simplest thing I did is to set focus on another view in onCreate:
myView.setFocusableInTouchMode(true);
myView.requestFocus();
This stopped the soft keyboard from coming up and there was no cursor flashing in the EditText.
Write this code inside the Manifest file in the Activity where you do not want to open the keyboard.
android:windowSoftInputMode="stateHidden"
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="24" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
**android:windowSoftInputMode="stateHidden"**
android:label="#string/app_name" >
</activity>
</application>
</manifest>
The easiest way to hide the keyboard is using setSoftInputMode
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or you can use InputMethodManager and hide the keyboard like this.
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
At onCreate of your Activity, just add use clearFocus() on your EditText element.
For example,
edittext = (EditText) findViewById(R.id.edittext);
edittext.clearFocus();
And if you want to divert the focus to another element, use requestFocus() on that.
For example,
button = (Button) findViewById(R.id.button);
button.requestFocus();

Categories

Resources