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
Related
I need to display a hint in the search box before the user clicks on it, as well as to have the search icon on the right.
In order to place the icon on the right, I used android:layoutDirection="rtl", but there were problems with the hint. If I set app:iconifiedByDefault="false", then the hint always starts to be displayed, but my search icon moves to the left.
my searchView code:
<androidx.appcompat.widget.SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/toolbar"
android:layout_marginTop="12dp"
app:searchIcon="#drawable/ic_search_button"
app:searchHintIcon="#null"
android:background="#drawable/shape_stroke_yellow"
app:queryBackground="#drawable/shape_stroke_yellow"
android:layoutDirection="rtl"
app:queryHint="#string/find_student"
>
</androidx.appcompat.widget.SearchView>
I saw Android 4.3: Not focus searchView not show hint , but this solution does not suit me, it is desirable to do everything through xml.
In other topics, the hint is solved everywhere by the line app:iconifiedByDefault="false", but then my icon is in the wrong place, so such solutions do not suit me either.
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 am creating an app and I need help.
I want to create a EditText and when the user open the keyboard to fill the edit text, that keyboard must have the "OK"or "Done" button inside it.
Example:
Thank you so much
You need to use ime options action done
You need to use single line (although deprecated)
example:
<EditText
android:id="#+id/saveDialogEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyz1234567890-_ ."
android:hint="#string/enter_palette_name_hint"
android:imeOptions="actionDone"
android:inputType="textAutoComplete"
android:singleLine="true"/>
I have a SearchActivty in my application on which I have an EditText and a Button to search the items. I want the search icon to be displayed in keyboard for this EditText.
Right now I've imeOption = "actionSearch" inside my EditText layout which is right now giving "search" as text in the keyboard. I want instead of text there should be an icon. IS it possible to set search icon on place of text in keyboard. If yes then please help.
My EditText in layout is :
<EditText
android:id="#+id/txtUser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="type name here"
android:inputType="text"
android:singleLine="true"
android:imeOptions="actionSearch"/>
No, its not possible. The keyboard itself decides what should be shown where. Some keyboards will implement images for various imeOptions, some won't. But there's no way to force it.
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.