Android: show hint before click on SearchView - android

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.

Related

Android: TextInputEditText showing text only after change focus

I have a big problem with a EditText that does not show any input until i change focus from element. When I click on the input, the keyboard appears and while i type, there is nothing displayed in the edit text view. The input is shown only when i close the keyboard
It is not a problem of colours. I mention that the view are contained in a constraint layout. I can enable hardware acceleration but this will slow down the application very much and it's not an option. I can however discard the constraint layout and change it to a linear layout but this will affect the rest of the code. I am sure that I am missing something, an easy fix, but i can't put my finger on it. Thanks a lot in advance
<android.support.design.widget.TextInputLayout
android:id="#+id/codeEditTextContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toTopOf="#id/verifyButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<android.support.design.widget.TextInputEditText
android:id="#+id/codeEditText"
android:layout_width="match_parent"
android:inputType="text"
android:layout_height="wrap_content"
android:hint="#string/sms_code"
android:padding="10dp"
android:textColor="#color/white" />
</android.support.design.widget.TextInputLayout>
!!UPDATE
Found the problem, but still i have no answer. This problem is present only on Android Pie and only when the edit text is in the lower part of the screen and has to be raised by the soft keyboard. I already tried to add softInputWindowMode to adjustResize or adjustPan but this is not doing anything.
The problem itself is a duplicate to this question Android Pie edittext does not adjustPan/resize while typing
which still doesn't have an answer
The problem man be about hardwareAccelerated. I was having the same problem and waste too much time to solve before saw this page.
Android Pie edittext does not adjustPan/resize while typing

Unwanted button text outline only in MotoG5

I have simple button
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#d22d2d"
android:text="Proceed"
android:textSize="35sp"
/>
On MotoG5 it shows unwanted outline on Button text, while it is okay in other devices.
This text outline does not appear in TextView. I tested it.
I checked another app in mobile, all apps (Gmail, Contacts etc.) having same behaviour.
I think there should be some theme fix to remove this unwanted outline in MotoG5.
You can disable it from Settings > Accessibility > Set off to High-contrast text
Your problem will solve.

How to style Android SearchView like in Google Play Store app?

I am trying to style a SearchView in a toolbar to look / behave like the SearchView in the Google Play Store app. It seems to wrap the searchview in a cardview but it also seems to integrate up button / drawer toggle behavior.
This is the main activity searchView, it has integrated drawer toggle
when you click on it, the drawer toggle changes to arrow (that when clicked will remove focus from the search view)
When you click on an app in the store, you go to app detail page and you have what looks like iconified version of the search view as a collapsed action item with up button:
Finally if you click on search icon it expands as an action item (with a kind of ripple animation) and displays all the way across the screen and incorporates the up button:
When I try to do it myself I have a lot of problems. I tried to wrap the searchview in a cardview and put that in a toolbar. It works but there is always padding on the left side that I can't remove (I tried contentInsetStart, doesn't work):
<android.support.v7.widget.Toolbar
android:id="#+id/activityCatalogToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:theme="#style/AppTheme.AppBarOverlay"
app:contentInsetStart="0dp"
app:contentInsetLeft="0dp">
<android.support.v7.widget.CardView
android:id="#+id/activityCatalogSearchContainer"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
app:cardCornerRadius="4dp"
app:cardElevation="8dp">
<android.support.v7.widget.SearchView
android:id="#+id/activityCatalogSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint=""
android:iconifiedByDefault="false"/>
</android.support.v7.widget.CardView>
</android.support.v7.widget.Toolbar>
I have also tried to remove the toolbar and replace it with just a FrameLayout. This allows me to control the padding but obviously I lose the toolbar functionalities (up button, etc) and also introduces theming problems (icons and text disappear).
Does anyone have an idea how they are doing this? I don't want to add another library just to style widgets that already exist in the framework. Thanks!
You might try to deep dive into this project:
https://android.googlesource.com/platform/packages/apps/Dialer/
For Lollipop or Marshmallow, or N it has a SearchEditTextLayout which is what you need:
Advantage
a code made by Google, not third party.
You have to use this Custom Implementation of SearchView.
https://github.com/Quinny898/PersistentSearch
Android Studio:
Add the Sonatype repository if you have not already:
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
Import it as a dependency:
compile 'com.quinny898.library.persistentsearch:library:1.1.0-SNAPSHOT'
In your layout:
<com.quinny898.library.persistentsearch.SearchBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchbox"
/>
Output :
I myself was trying to build this. Ended up just making the search button an ImageButton. a click on this would Trigger a Fragment to be added on top which would contain an Edittext inside an layout made to look like this. and this Fragment consisted of a listview below this searchbox to show suggestions.
Tip: Keep the Fragment's rootlayout without any background and set clickable to true to achieve best results with a transparent pane

cwac RichEditText not working

It appears trivial even on the 'Usage' section here
My edit text appears just the same, when i type on it everything appears as usual, when i select text everything is still normal. No "FORMAT" entry on the action mode. What am I doing wrong??
My layout:
<com.commonsware.cwac.richedit.RichEditText
android:id="#+id/editTextSermon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:hint="#string/type_the_sermon_here"
android:lines="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine">
<requestFocus/>
</com.commonsware.cwac.richedit.RichEditText>
In my activity:
sermonText = (RichEditText) findViewById(R.id.editTextSermon);
sermonText.enableActionModes(true);
From the documentation that is all I need to do, or is it?
On a side note part of the documentation reads like this:
On its own, by default, RichEditText provides one means of users applying formatting: the standard Ctrl-B for bold, Ctrl-I for italics, and Ctrl-U for underline work if there is a selection.
I've never seen a 'Control' button on an android keyboard. Whats going on? I just want to be able to bold, italicize and underline my text.

SearchView show as always

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

Categories

Resources