android: get rid of focus when enter activity [duplicate] - android

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Stop EditText from gaining focus at Activity startup?
I have an activity has a EditText inside, and each time when the activity starts up, the EditText automatically get the focus.
I don't want the EditText gets the focus automatically, how can I do?

I had the similar issue and i am sure this is the problem, for that you just need to do a small trick.
Add this LinearLayout before the EditText which is getting focus at activity startup. You don't need to set any value inside the EditText.
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0dip"
android:layout_height="0dip"
android:id="#+id/dummyView"/>

Add this in <activity> tag in your manifest for activity in which edittext is present.
android:windowSoftInputMode="stateHidden"

put android:focusable="false" may it will work for edittext

Related

android - edittext keyboard not showing

I am creating an edittext programmatically. But I was not able to type anything into the edittext. I have covered all the related answers on this site but none of them worked for me. Maybe I am missing some minor details. It would be helpful if I can get some help.
Code to create edittext dynamically:
EditText editText = new EditText(dt.c);
editText.setBackground(context.getResources().getDrawable(R.drawable.rectangle_answer));
editText.setTextColor(ContextCompat.getColor(dt.c, R.color.md_black_1000));
editText.setTextSize(16);
editText.setTag(questionDetails[0].getOptionId());
editText.setFocusable(true);
editText.setHint(dt.gStr(R.string.enter_your_answer));
editText.requestFocus();
container.Add(editText);
Some of the answers that I covered:
How can I set the focus (and display the keyboard) on my EditText programmatically
Android - EditText made programmatically not showing keyboard
Android: How to open keyboard for editing EditText when click button?
Disable keyboard on EditText
How to disable the keyboard when I click on EditText?
I was having the same problem and nothing worked until I found an answer way down in one of the posts from years ago that worked. I'll repost the weird hack for anyone who might have this problem in the future.
In your xml file, add a dummy edittext to your topmost layout layer that looks like this:
<EditText
android:id="#+id/editTextFix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
tools:targetApi="o"
android:inputType="text"
android:visibility="gone"/>
the dummy edittext will open the keyboard, but your programatically created edittext will still have focus.

Keyboard covers Exidtext field [duplicate]

This question already has answers here:
How to adjust layout when soft keyboard appears
(18 answers)
Closed 5 years ago.
The Edittext field is covered with the current keyboard.
People don't see what they are typing at the moment. The page is a fragment.
Here is a XML layout of the mentioned Edittext:
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/commentEditText"
android:windowSoftInputMode="adjustPan"
android:hint="Opmerkingen" />
It doesn't work. Maybe I'm doing it the wrong way. Can you help me to solve it?
https://i.stack.imgur.com/XmuXm.png
use android:windowSoftInputMode=adjustPan in mainfiest file inside activity
use like this see example
<activity
android:name=".activity"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden">
</activity>
You can try using android:windowSoftInputMode="adjustResize" in your activity's manifest file, which will resize your screen to fit keyboard.
If user still cannot see input on EditText you can try android:windowSoftInputMode="adjustPan", which does not resize screen to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.
Add this line to your activity tag in Menifest file,
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"/>

Android EditText not Multi Line [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
restrict edittext to single line
I have 2 edit texts. My problem is, when I press the enter button in the keyboard, it creates another set of line. Or it creates like a next line in my edit text. I want to remove it and I want it to be in single line. Even if I enter the enter key in the keyboard, still it won't create a next line.
How do you do it?
Try this in your EditText xml
android:singleLine="true"
<EditText
android:id="#+id/edittextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:singleLine="true"/>
Try this with your edit text in layout

EditText doesn't start automatically

In my app, I have an EditText. How do I make it doesn't start automatically? Like: once they open the activity it automatically sets the mouse to the EditText and the keyboard gets opened so they type…
Is there anyway I can make it open (the keyboard shows and the user can type) when they clicks on it?
Ok, so from your question i figure out that your EditText is getting focus while starting the activity. You can disable the focus using following command to suppress the keyboard.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Visit this Close/hide the Android Soft Keyboard
the answer by Lucifer must work. But when i got the same problem, that solution did't work, and someone suggested me this.
add a fake layout as the first element in you parent layout and make it focusable.
Like this:
<ParentLayout
.....
......>
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:focusable="true"
android:focusableInTouchMode="true" >
</LinearLayout>
......
......
......
</ParentLayout>
This definitely works, but the best solution is:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

How to get focus for a button in between two editfields in android

i am having a button in between two edit fields. when iam using track ball to scroll ,button is getting focus but when i use the next button in softkeyboard after typing some text in editfield , focus is moving on to next editfield but not the button inbetween them .how to solve this..?
Use android:focusableInTouchMode attribute:
<Button ... android:focusableInTouchMode="true" />
I think android:nextFocusDown and android:nextFocusUp solves your problem.

Categories

Resources