I have a table whose tapping on a cell changes its content and displays some edit texts. The first of these edit texts requests the focus, but oddly when I tap on it, the keyboard doesn't show. It is when I tap the others edit texts though. What should I do? Here is how I implemented my first edit text.
<EditText
android:id="#+id/editContent"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="top"
android:inputType="textMultiLine" >
</requestFocus>
</EditText>
When I don't request the focus, there is also a strange behaviour: it opens the keyboard when I tap it but my edit text loses the focus and I've to tap it again to write in it.
I found the problem, it was because of this line in the Activity block of the Manifest :
android:windowSoftInputMode="stateHidden"
I changed it by :
android:windowSoftInputMode="adjustPan"
Works well now.
Related
I have followed this solution on preventing edit text from taking focus on activity startup. And implemented it as such
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:text="#string/zero"
android:gravity="end|center_vertical"
android:nextFocusUp="#id/amount"
android:nextFocusLeft="#id/amount"
android:inputType="numberDecimal"/>
Notice the android:inputType="numberDecimal". If I remove that then upon startup the focus is not taken, however if it is there then focus is taken. Is there any way to get decimal edit text to not take focus upon startup? I am using API > 23 if it is of any concern.
And just as a side note from looking at answers other people provided to similar questions, I want my field to not take focus. I do not want to only hide the soft keyboard but keep the focus.
Add this to your activity tag in manifest
android:windowSoftInputMode="stateHidden|adjustResize"
Code looks like in manifest
<activity
android:name=".ActivityName"
android:windowSoftInputMode="stateHidden|adjustResize" />
This will help hide soft keyboard at startup
And add these tags to your root layout rather than parent layout
android:focusable="true"
android:focusableInTouchMode="true"
I have 2 layouts with EditText widget in them. In the first one EditText automatically receives focus on activity's start but shows no software keyboard (this is the desired behaviour). In the second layout, however, EditText is focused and shows soft-keyboard. I examined both layouts and can't find a reason for this behavour, because both widgets have identical properties. Soft-keyboard should only be displayed when I touch the input field. Am I missing something?
<EditText
android:id="#+id/scanLine"
android:layout_width="253.0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="19.0dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:inputType="text"
android:maxLines="1"
android:focusableInTouchMode="true" />
Add the following line to the onCreate() method of your activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Hope it helps!
Hard to explain with words, but you can see what I'm talking about easily in Google Hangouts. When you tap in the EditText at the bottom to enter a comment, you see some buttons between the bottom of the EditText and the soft keyboard.
How do you do that? I made a simple layout that has an EditText and a Button below it, but when the user taps in the EditText, the Button is obscured by the soft keyboard. Here's a cleaned up sample:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/StandardMarginSmall"
android:layout_marginBottom="#dimen/StandardMarginSmall">
<EditText
android:id="#+id/NewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>
<Button
android:id="#+id/PostComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Post"
/>
</LinearLayout>
Is there a trick into forcing it to keep those buttons viewable while in edit mode?
If you set android:windowSoftInputMode="adjustResize" on your activity, when the softkeyboard is shown, it will push the content of your activity up (resizing it), instead of overlaying on top of your activity. You'll be able to show the buttons then (they'll just be at the bottom of the layout of your activity).
i use widget SearchView
<SearchView
android:id="#+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/white"
android:inputType="text"
android:singleLine="true"
android:layout_alignParentLeft="true"
/>
its work fine , but if search box show up, i always have to click on search icon then. so can anyone help me to make search box show up without click on search icon
Add the attribute
android:iconifiedByDefault="false"
to the SearchView definition.
You can add android:windowSoftInputMode="stateHidden" to the activity in the manifest file to prevent the keyboard from displaying; but before you do, think about this: If the user is forced to touch the widget to display the keyboard and enter something, you might as well leave the searchview iconified so that the user can see more of the display underneath.
If you really want to remove focus, there are a few alternatives, see this post: Stop EditText from gaining focus at Activity startup
i want to show both because i have 3 edit text and in 2 second edit text i want to show both option on soft keyboard so that user can go to previous or next edit text, is there anyway to do this? here is my code can
<EditText
android:id="#+id/etxtrunner"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtrunner"
android:layout_alignBottom="#+id/txtrunner"
android:layout_alignRight="#+id/qrcode_img"
android:background="#color/gray"
android:singleLine="true"
android:imeOptions="actionNext"
android:ems="10" />
This question is a duplicate, yet, you can see that you can not have both next/previous button together in this answer.
However, you can make a makeshift solution like this.