How to make EditText not focused when creating Activity
up vote
60
down vote
favorite
Before you downvote and mark as duplicate, read my question.
I've read the other questions discussing this, and all of them work for my layouts, except for the very first one created.
At the moment, this is at the top of my onCreate method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
^ That makes it so at least the keyboard doesn't pop up on startup, but the EditText is still focused on.
This is the XML for my EditText:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
This is what it looks like when I bring up my activity:

The problem is that with some phones, when an EditText is focused like this, they can't write in it. I want it to not focus.
What I've done works for the next layouts brought up in that it the EditTexts are not focused on and would look more like this:

Notice that it's the same layout, though. This is the screen after the user has been brought back to this screen, which would indicate nothing wrong with the XML because this is the same XML, but the problem is that the EditText is only focused on when the activity is created.
I've done research and all of the other questions don't help me with this (they did however help the keyboard not show up, thankfully). How can I make it so the EditText on startup will look like the second screenshot, rather than the first?
java
add a comment |
up vote
60
down vote
favorite
Before you downvote and mark as duplicate, read my question.
I've read the other questions discussing this, and all of them work for my layouts, except for the very first one created.
At the moment, this is at the top of my onCreate method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
^ That makes it so at least the keyboard doesn't pop up on startup, but the EditText is still focused on.
This is the XML for my EditText:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
This is what it looks like when I bring up my activity:

The problem is that with some phones, when an EditText is focused like this, they can't write in it. I want it to not focus.
What I've done works for the next layouts brought up in that it the EditTexts are not focused on and would look more like this:

Notice that it's the same layout, though. This is the screen after the user has been brought back to this screen, which would indicate nothing wrong with the XML because this is the same XML, but the problem is that the EditText is only focused on when the activity is created.
I've done research and all of the other questions don't help me with this (they did however help the keyboard not show up, thankfully). How can I make it so the EditText on startup will look like the second screenshot, rather than the first?
java
so you want to focus onEditText?
– Pratik Butani
Aug 18 '13 at 4:59
2
Have you triedandroid:focusable="false"inEditText?
– Pratik Butani
Aug 18 '13 at 5:08
@PratikButani that makes it so it can never be focused on, though.
– Michael Yaworski
Aug 18 '13 at 5:15
Addingandroid:focusableInTouchMode="true"on my parent layout works for me.
– Marcelo Gracietti
May 12 '17 at 15:05
add a comment |
up vote
60
down vote
favorite
up vote
60
down vote
favorite
Before you downvote and mark as duplicate, read my question.
I've read the other questions discussing this, and all of them work for my layouts, except for the very first one created.
At the moment, this is at the top of my onCreate method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
^ That makes it so at least the keyboard doesn't pop up on startup, but the EditText is still focused on.
This is the XML for my EditText:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
This is what it looks like when I bring up my activity:

The problem is that with some phones, when an EditText is focused like this, they can't write in it. I want it to not focus.
What I've done works for the next layouts brought up in that it the EditTexts are not focused on and would look more like this:

Notice that it's the same layout, though. This is the screen after the user has been brought back to this screen, which would indicate nothing wrong with the XML because this is the same XML, but the problem is that the EditText is only focused on when the activity is created.
I've done research and all of the other questions don't help me with this (they did however help the keyboard not show up, thankfully). How can I make it so the EditText on startup will look like the second screenshot, rather than the first?
java
Before you downvote and mark as duplicate, read my question.
I've read the other questions discussing this, and all of them work for my layouts, except for the very first one created.
At the moment, this is at the top of my onCreate method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
^ That makes it so at least the keyboard doesn't pop up on startup, but the EditText is still focused on.
This is the XML for my EditText:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
This is what it looks like when I bring up my activity:

The problem is that with some phones, when an EditText is focused like this, they can't write in it. I want it to not focus.
What I've done works for the next layouts brought up in that it the EditTexts are not focused on and would look more like this:

Notice that it's the same layout, though. This is the screen after the user has been brought back to this screen, which would indicate nothing wrong with the XML because this is the same XML, but the problem is that the EditText is only focused on when the activity is created.
I've done research and all of the other questions don't help me with this (they did however help the keyboard not show up, thankfully). How can I make it so the EditText on startup will look like the second screenshot, rather than the first?
java
java
edited Dec 8 '13 at 19:01
asked Aug 18 '13 at 4:50
Michael Yaworski
9,304144779
9,304144779
so you want to focus onEditText?
– Pratik Butani
Aug 18 '13 at 4:59
2
Have you triedandroid:focusable="false"inEditText?
– Pratik Butani
Aug 18 '13 at 5:08
@PratikButani that makes it so it can never be focused on, though.
– Michael Yaworski
Aug 18 '13 at 5:15
Addingandroid:focusableInTouchMode="true"on my parent layout works for me.
– Marcelo Gracietti
May 12 '17 at 15:05
add a comment |
so you want to focus onEditText?
– Pratik Butani
Aug 18 '13 at 4:59
2
Have you triedandroid:focusable="false"inEditText?
– Pratik Butani
Aug 18 '13 at 5:08
@PratikButani that makes it so it can never be focused on, though.
– Michael Yaworski
Aug 18 '13 at 5:15
Addingandroid:focusableInTouchMode="true"on my parent layout works for me.
– Marcelo Gracietti
May 12 '17 at 15:05
so you want to focus on
EditText?– Pratik Butani
Aug 18 '13 at 4:59
so you want to focus on
EditText?– Pratik Butani
Aug 18 '13 at 4:59
2
2
Have you tried
android:focusable="false" in EditText ?– Pratik Butani
Aug 18 '13 at 5:08
Have you tried
android:focusable="false" in EditText ?– Pratik Butani
Aug 18 '13 at 5:08
@PratikButani that makes it so it can never be focused on, though.
– Michael Yaworski
Aug 18 '13 at 5:15
@PratikButani that makes it so it can never be focused on, though.
– Michael Yaworski
Aug 18 '13 at 5:15
Adding
android:focusableInTouchMode="true" on my parent layout works for me.– Marcelo Gracietti
May 12 '17 at 15:05
Adding
android:focusableInTouchMode="true" on my parent layout works for me.– Marcelo Gracietti
May 12 '17 at 15:05
add a comment |
13 Answers
13
active
oldest
votes
up vote
270
down vote
accepted
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true"
Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</RelativeLayout>
May this one helpful ;)
add a comment |
up vote
16
down vote
XML code:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
Java code:
EditText edPwd = (EditText)findViewById(R.id.password);
edtPwd.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}
});
set focusable false in xml and set it true via the code
Good solution ... the answer marked correct results in the IME optionactionNextfailing completely.
– Y.S.
Sep 3 '15 at 13:42
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
add a comment |
up vote
12
down vote
In your main_layout
add this 2 lines:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> *YOUR LAYOUT CODE* </RelativeLayout>
1
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
add a comment |
up vote
2
down vote
Add this in onCreate()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or in onCreateView()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
add a comment |
up vote
1
down vote
XML Code
<EditText
android:imeOptions="flagNoExtractUi"
android:focusable="false"
/>
Java Code in onClickListerner
mEdtEnterPhoneNumber.setFocusable(true);
mEdtEnterPhoneNumber.setFocusableInTouchMode(true);
add a comment |
up vote
1
down vote
the best solution is here:
https://stackoverflow.com/a/45139132/3172843
the correct and simple solution is to setFocusable false and setFocusableInTouchMode true . so the EditText gain focus only when user touch that EditText
android:focusable="false"
android:focusableInTouchMode="true"
add a comment |
up vote
0
down vote
You can do this programmatically. use editText.setEnabled(false) in your onStart() method of your activity (not in onCreate() - because this is some method for initializing GUI components)
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
add a comment |
up vote
0
down vote
It is possible to use android:focusable="false" to disable it, but if that does not work for some reason, then you can simply put a LinearLayout and it will take the focus without disrupting your layout.
NOTE: Eclipse will give you an error saying that your LinearLayout is useless because it has no contents. You should be able to disregard it with no problems.
For example:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="false"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</LinearLayout>
add a comment |
up vote
0
down vote
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
android:windowSoftInputMode="stateAlwaysHidden"
add this line in the activity tag of the Manifest.xml file.when you click on the TextEdit the keyboard gets into focus.
add a comment |
up vote
0
down vote
The easiest way is to add
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
in the activity tag of the Manifest.xml file
add a comment |
up vote
0
down vote
1) Its the simplest,open the manifest and put the following code between the activity tag:
android:windowSoftInputMode="stateHidden"
2) Put this attributes in the parent layout
android:focusable="true"
android:focusableInTouchMode="true"
add a comment |
up vote
0
down vote
In Manifest , copy and paste the beneath code.
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
add a comment |
up vote
-6
down vote
use android:focusable="false" for focusing disable
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30"
android:focusable="false" >
</EditText>
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
add a comment |
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
270
down vote
accepted
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true"
Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</RelativeLayout>
May this one helpful ;)
add a comment |
up vote
270
down vote
accepted
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true"
Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</RelativeLayout>
May this one helpful ;)
add a comment |
up vote
270
down vote
accepted
up vote
270
down vote
accepted
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true"
Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</RelativeLayout>
May this one helpful ;)
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true"
Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</RelativeLayout>
May this one helpful ;)
edited Sep 28 '17 at 17:17
Adeel
2,06961424
2,06961424
answered Aug 18 '13 at 5:12
Pratik Butani
28.8k25142256
28.8k25142256
add a comment |
add a comment |
up vote
16
down vote
XML code:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
Java code:
EditText edPwd = (EditText)findViewById(R.id.password);
edtPwd.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}
});
set focusable false in xml and set it true via the code
Good solution ... the answer marked correct results in the IME optionactionNextfailing completely.
– Y.S.
Sep 3 '15 at 13:42
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
add a comment |
up vote
16
down vote
XML code:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
Java code:
EditText edPwd = (EditText)findViewById(R.id.password);
edtPwd.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}
});
set focusable false in xml and set it true via the code
Good solution ... the answer marked correct results in the IME optionactionNextfailing completely.
– Y.S.
Sep 3 '15 at 13:42
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
add a comment |
up vote
16
down vote
up vote
16
down vote
XML code:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
Java code:
EditText edPwd = (EditText)findViewById(R.id.password);
edtPwd.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}
});
set focusable false in xml and set it true via the code
XML code:
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
Java code:
EditText edPwd = (EditText)findViewById(R.id.password);
edtPwd.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}
});
set focusable false in xml and set it true via the code
edited Dec 8 '13 at 19:15
Michael Yaworski
9,304144779
9,304144779
answered Aug 18 '13 at 5:14
Meher
258111
258111
Good solution ... the answer marked correct results in the IME optionactionNextfailing completely.
– Y.S.
Sep 3 '15 at 13:42
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
add a comment |
Good solution ... the answer marked correct results in the IME optionactionNextfailing completely.
– Y.S.
Sep 3 '15 at 13:42
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
Good solution ... the answer marked correct results in the IME option
actionNext failing completely.– Y.S.
Sep 3 '15 at 13:42
Good solution ... the answer marked correct results in the IME option
actionNext failing completely.– Y.S.
Sep 3 '15 at 13:42
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
I tried it first it didn't work, my bad I was testing on emulator with no touch screen, On real device its working like a charm, Thanks @Meher
– Syeda Zunairah
May 19 '16 at 11:57
add a comment |
up vote
12
down vote
In your main_layout
add this 2 lines:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> *YOUR LAYOUT CODE* </RelativeLayout>
1
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
add a comment |
up vote
12
down vote
In your main_layout
add this 2 lines:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> *YOUR LAYOUT CODE* </RelativeLayout>
1
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
add a comment |
up vote
12
down vote
up vote
12
down vote
In your main_layout
add this 2 lines:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> *YOUR LAYOUT CODE* </RelativeLayout>
In your main_layout
add this 2 lines:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> *YOUR LAYOUT CODE* </RelativeLayout>
answered Feb 8 '16 at 9:21
avisper
35249
35249
1
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
add a comment |
1
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
1
1
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
Edit Text is not focused but the keyboard is visible.
– viper
Jan 3 '17 at 4:29
add a comment |
up vote
2
down vote
Add this in onCreate()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or in onCreateView()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
add a comment |
up vote
2
down vote
Add this in onCreate()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or in onCreateView()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
add a comment |
up vote
2
down vote
up vote
2
down vote
Add this in onCreate()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or in onCreateView()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Add this in onCreate()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or in onCreateView()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
answered Mar 16 '17 at 5:41
Sanket Parchande
488613
488613
add a comment |
add a comment |
up vote
1
down vote
XML Code
<EditText
android:imeOptions="flagNoExtractUi"
android:focusable="false"
/>
Java Code in onClickListerner
mEdtEnterPhoneNumber.setFocusable(true);
mEdtEnterPhoneNumber.setFocusableInTouchMode(true);
add a comment |
up vote
1
down vote
XML Code
<EditText
android:imeOptions="flagNoExtractUi"
android:focusable="false"
/>
Java Code in onClickListerner
mEdtEnterPhoneNumber.setFocusable(true);
mEdtEnterPhoneNumber.setFocusableInTouchMode(true);
add a comment |
up vote
1
down vote
up vote
1
down vote
XML Code
<EditText
android:imeOptions="flagNoExtractUi"
android:focusable="false"
/>
Java Code in onClickListerner
mEdtEnterPhoneNumber.setFocusable(true);
mEdtEnterPhoneNumber.setFocusableInTouchMode(true);
XML Code
<EditText
android:imeOptions="flagNoExtractUi"
android:focusable="false"
/>
Java Code in onClickListerner
mEdtEnterPhoneNumber.setFocusable(true);
mEdtEnterPhoneNumber.setFocusableInTouchMode(true);
answered Jun 16 '16 at 3:24
Hai Rom
90187
90187
add a comment |
add a comment |
up vote
1
down vote
the best solution is here:
https://stackoverflow.com/a/45139132/3172843
the correct and simple solution is to setFocusable false and setFocusableInTouchMode true . so the EditText gain focus only when user touch that EditText
android:focusable="false"
android:focusableInTouchMode="true"
add a comment |
up vote
1
down vote
the best solution is here:
https://stackoverflow.com/a/45139132/3172843
the correct and simple solution is to setFocusable false and setFocusableInTouchMode true . so the EditText gain focus only when user touch that EditText
android:focusable="false"
android:focusableInTouchMode="true"
add a comment |
up vote
1
down vote
up vote
1
down vote
the best solution is here:
https://stackoverflow.com/a/45139132/3172843
the correct and simple solution is to setFocusable false and setFocusableInTouchMode true . so the EditText gain focus only when user touch that EditText
android:focusable="false"
android:focusableInTouchMode="true"
the best solution is here:
https://stackoverflow.com/a/45139132/3172843
the correct and simple solution is to setFocusable false and setFocusableInTouchMode true . so the EditText gain focus only when user touch that EditText
android:focusable="false"
android:focusableInTouchMode="true"
answered Jul 17 '17 at 8:18
faraz khonsari
1,043922
1,043922
add a comment |
add a comment |
up vote
0
down vote
You can do this programmatically. use editText.setEnabled(false) in your onStart() method of your activity (not in onCreate() - because this is some method for initializing GUI components)
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
add a comment |
up vote
0
down vote
You can do this programmatically. use editText.setEnabled(false) in your onStart() method of your activity (not in onCreate() - because this is some method for initializing GUI components)
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
add a comment |
up vote
0
down vote
up vote
0
down vote
You can do this programmatically. use editText.setEnabled(false) in your onStart() method of your activity (not in onCreate() - because this is some method for initializing GUI components)
You can do this programmatically. use editText.setEnabled(false) in your onStart() method of your activity (not in onCreate() - because this is some method for initializing GUI components)
answered Jan 6 '16 at 9:40
Nicole Conrad
172
172
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
add a comment |
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
This would completely disable the EditText, which is not what is needed. I'm not sure (because I haven't tested), but I don't think disabling and then re-enabling would work either. Unless there's something I'm missing, make sure you understand the question.
– Michael Yaworski
Jan 6 '16 at 19:41
add a comment |
up vote
0
down vote
It is possible to use android:focusable="false" to disable it, but if that does not work for some reason, then you can simply put a LinearLayout and it will take the focus without disrupting your layout.
NOTE: Eclipse will give you an error saying that your LinearLayout is useless because it has no contents. You should be able to disregard it with no problems.
For example:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="false"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</LinearLayout>
add a comment |
up vote
0
down vote
It is possible to use android:focusable="false" to disable it, but if that does not work for some reason, then you can simply put a LinearLayout and it will take the focus without disrupting your layout.
NOTE: Eclipse will give you an error saying that your LinearLayout is useless because it has no contents. You should be able to disregard it with no problems.
For example:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="false"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</LinearLayout>
add a comment |
up vote
0
down vote
up vote
0
down vote
It is possible to use android:focusable="false" to disable it, but if that does not work for some reason, then you can simply put a LinearLayout and it will take the focus without disrupting your layout.
NOTE: Eclipse will give you an error saying that your LinearLayout is useless because it has no contents. You should be able to disregard it with no problems.
For example:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="false"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</LinearLayout>
It is possible to use android:focusable="false" to disable it, but if that does not work for some reason, then you can simply put a LinearLayout and it will take the focus without disrupting your layout.
NOTE: Eclipse will give you an error saying that your LinearLayout is useless because it has no contents. You should be able to disregard it with no problems.
For example:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="false"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30" >
</EditText>
</LinearLayout>
edited Oct 3 '16 at 9:05
Pratik Butani
28.8k25142256
28.8k25142256
answered Aug 18 '13 at 5:16
ThatGuyThere
1751921
1751921
add a comment |
add a comment |
up vote
0
down vote
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
android:windowSoftInputMode="stateAlwaysHidden"
add this line in the activity tag of the Manifest.xml file.when you click on the TextEdit the keyboard gets into focus.
add a comment |
up vote
0
down vote
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
android:windowSoftInputMode="stateAlwaysHidden"
add this line in the activity tag of the Manifest.xml file.when you click on the TextEdit the keyboard gets into focus.
add a comment |
up vote
0
down vote
up vote
0
down vote
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
android:windowSoftInputMode="stateAlwaysHidden"
add this line in the activity tag of the Manifest.xml file.when you click on the TextEdit the keyboard gets into focus.
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
android:windowSoftInputMode="stateAlwaysHidden"
add this line in the activity tag of the Manifest.xml file.when you click on the TextEdit the keyboard gets into focus.
answered Oct 5 '17 at 7:26
pruthwiraj.kadam
18917
18917
add a comment |
add a comment |
up vote
0
down vote
The easiest way is to add
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
in the activity tag of the Manifest.xml file
add a comment |
up vote
0
down vote
The easiest way is to add
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
in the activity tag of the Manifest.xml file
add a comment |
up vote
0
down vote
up vote
0
down vote
The easiest way is to add
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
in the activity tag of the Manifest.xml file
The easiest way is to add
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
in the activity tag of the Manifest.xml file
answered Feb 26 at 9:44
Sudhir singh
144210
144210
add a comment |
add a comment |
up vote
0
down vote
1) Its the simplest,open the manifest and put the following code between the activity tag:
android:windowSoftInputMode="stateHidden"
2) Put this attributes in the parent layout
android:focusable="true"
android:focusableInTouchMode="true"
add a comment |
up vote
0
down vote
1) Its the simplest,open the manifest and put the following code between the activity tag:
android:windowSoftInputMode="stateHidden"
2) Put this attributes in the parent layout
android:focusable="true"
android:focusableInTouchMode="true"
add a comment |
up vote
0
down vote
up vote
0
down vote
1) Its the simplest,open the manifest and put the following code between the activity tag:
android:windowSoftInputMode="stateHidden"
2) Put this attributes in the parent layout
android:focusable="true"
android:focusableInTouchMode="true"
1) Its the simplest,open the manifest and put the following code between the activity tag:
android:windowSoftInputMode="stateHidden"
2) Put this attributes in the parent layout
android:focusable="true"
android:focusableInTouchMode="true"
answered Sep 18 at 8:23
Vincent Mungai
6922
6922
add a comment |
add a comment |
up vote
0
down vote
In Manifest , copy and paste the beneath code.
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
add a comment |
up vote
0
down vote
In Manifest , copy and paste the beneath code.
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
add a comment |
up vote
0
down vote
up vote
0
down vote
In Manifest , copy and paste the beneath code.
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
In Manifest , copy and paste the beneath code.
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
answered Nov 9 at 7:57
Agilanbu
799617
799617
add a comment |
add a comment |
up vote
-6
down vote
use android:focusable="false" for focusing disable
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30"
android:focusable="false" >
</EditText>
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
add a comment |
up vote
-6
down vote
use android:focusable="false" for focusing disable
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30"
android:focusable="false" >
</EditText>
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
add a comment |
up vote
-6
down vote
up vote
-6
down vote
use android:focusable="false" for focusing disable
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30"
android:focusable="false" >
</EditText>
use android:focusable="false" for focusing disable
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/changePass"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="30"
android:focusable="false" >
</EditText>
edited Dec 8 '13 at 19:16
Michael Yaworski
9,304144779
9,304144779
answered Aug 18 '13 at 5:07
Mohammod Hossain
3,50921830
3,50921830
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
add a comment |
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
it works, but that makes it so it can never be focused on, even after touching.
– Michael Yaworski
Aug 18 '13 at 5:15
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
you can use event listener when you need to make it focusable
– Mohammod Hossain
Aug 18 '13 at 5:18
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
edit your answer to have that, and I'll vote you up. Someone already answered with what you said, though.
– Michael Yaworski
Aug 18 '13 at 5:21
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18295802%2fhow-to-make-edittext-not-focused-when-creating-activity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
so you want to focus on
EditText?– Pratik Butani
Aug 18 '13 at 4:59
2
Have you tried
android:focusable="false"inEditText?– Pratik Butani
Aug 18 '13 at 5:08
@PratikButani that makes it so it can never be focused on, though.
– Michael Yaworski
Aug 18 '13 at 5:15
Adding
android:focusableInTouchMode="true"on my parent layout works for me.– Marcelo Gracietti
May 12 '17 at 15:05