I'm currently developing a simple apps using Android Studio with the minimum API Level 8, now i currently using android.support.v7.widget.SearchView in my LinearLayout in content_main.xml layout, not on ACTIONBAR, now the problem is, i'm not able to set the searchView as Expanded by default, i already look for solution and i only got this:
android:iconifiedByDefault="false"
here is my full code for my searchView
<android.support.v7.widget.SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:background="#00000000"
android:iconifiedByDefault="false"
android:layout_weight="1" />
but no luck, it's not working. anyone could help me? any help would be appreciated. Thank you so much!
Ok, so i solve the problem. to anyone who want to use support library for SearchView here's how you can customize it.
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:closeIcon="#drawable/ic_clear" // To set custom clear icon
app:searchIcon="#drawable/ic_search" //To set custom search icon
app:queryBackground="#color/transparent" // i decided to remove underline so i create a custom background for my searchView
app:queryHint="#string/filterHint" //to set a custom Hint
app:iconifiedByDefault="false" //And finally, to Expand it as default
/>
as i said, i'm afraid of overriding xml layout on runtime via java code, so to make it organize and no more overriding during the runtime, this is how i do it.
Reference
Thanks for help!!!
I used the below code to expand the searchview and place the cursor at the same time:
final SearchView sv = new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext());
sv.setIconifiedByDefault(true);
sv.setFocusable(true);
sv.setIconified(false);
sv.clearFocus();
sv.requestFocusFromTouch();
To make the SearchView expanded by default, call setIconifiedByDefault(false) on it when you initialise it (e.g. in onCreate(..) . I've found in most cases this will give it focus automatically, but if not simply call requestFocus() on it too.
Related
This is how I want to show the value of the slider. Please find the picture
This is currently not supported, the available options in LabelFormatter (which can be applied to sliders with slider.setLabelFormatter(...) are:
LabelFormatter.LABEL_FLOATING: Label visible during interaction only
LabelFormatter.LABEL_WITHIN_BOUNDS: Label visible during interaction only
LabelFormatter.LABEL_GONE: Label never visible
You can find the code here with the extensive javadoc explanation.
You could open a feature request for this on the Material GitHub issues page
You can set the label behaviour "visible" in the XML file. So in the slider XML code, you just need to add
app:labelBehavior="visible"
Below I am attaching a sample XML code for the same.
<com.google.android.material.slider.Slider
android:id="#+id/seek_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:valueFrom="1"
android:valueTo="100"
android:layout_gravity="center"
android:layout_margin="15dp"
app:tickColor="#0000FF"
app:labelStyle="#style/Tooltip"
app:labelBehavior="visible"
/>
I have noticed that since a few days, all my TextInputLayouts have the "error exclamation point" always enabled. I haven't changed anything about those TextInputLayouts for a long time, so I really don't understand what is happening.
Here is a screenshot of how it looks:
Do you have have any idea what could be the source of this issue? Did something recently changed with the TextInputLayouts?
Thank you very much in advance
EDIT
Here is the related code:
The .xml file is really simple. It's a list of TextInputLayouts and EditTexts like this:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/default_margin"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginRight="#dimen/default_margin">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/txtAddressTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/PROFILE_SCREEN_ADDRESS_INPUT_TITLE"
android:inputType="textPersonName|textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
Also, there absolutely no mention of setError() in my Kotlin code.
You can try this. But It will permanently remove the error Icon. If you want to show it again you have do it programmatically.
app:errorIconDrawable="#null"
Edit:
It looks like it's fixed with com.google.android.material:material:1.2.0-alpha04.
Ho, I found the issue. I actually updated the version of the Material library from version com.google.android.material:material:1.1.0-alpha08 to com.google.android.material:material:1.1.0-alpha09.
Google changed the behaviour of Text Field (see here: https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha09):
Text Field:
Adding option to set TextInputLayout icons to be not checkable (6a88f2b)
Implementing error icon for text fields (3f73804)
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
I already looked at Styling android search view and drop down list in actionbar and it only works if the SearchView is in the ActionBar. The problem is I have two SearchViews. The one in the ActionBar works well with the suggested changes. But the other one, which is just inside a layout, is not working. How do I fix it? I tried applying the appTheme style to it, still nothing
<android.support.v7.widget.SearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/AppTheme"
android:background="#color/colorPrimaryLight"
>
</android.support.v7.widget.SearchView>
try to use spinner way for this
adapter = new ArrayAdapter(this,R.layout.simple_spinner_item,itemList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item,listitems);
spinner.setAdapter(adapter);
may be helpfull
I want to implement searchView like this link and link2 but I want to make a search from own EditText not in ActioBar or in menu.
I want to know what is the code in the main layout xml file. consider that I'm not want to use ActionBar with menu item because it isn't supported for api less that level 11, I want to use the search and get result in the same Activity, all what I want to know how can I get the search bar when press a button to give it a word t search in sqlite and get the result in the same Activity?
Hope anyone got my mean.
Thanks in advance.
Do not use a EditText, it is much easier to use a SearchView. If you don't want to have search interface in the action bar, then you can use a search widget, which is an instance of SearchView.
The basics are here : http://developer.android.com/guide/topics/search/search-dialog.html
If you really do not want the ActionBar and have to support older API levels than API level 11 (Honeycomb) and do not want to use a search dialog, you have to do everything on your own.
You could use a AutoCompleteTextView to display search suggestions and start an activity / fragment to display a list of results with the query entered whenever the user triggers your search. That's not different from any other Activity that has to react to user input.
But I strongly suggest to use ActionBarCompat and the support library to provide an ActionBar on older devices and use the SearchView within the ActionBar. That's what users expect nowadays anyway and it makes development that much easier.
If you want to create a search box using EditText (not in Action Bar), you may refer to the following XML code:
<RelativeLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/inputSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:hint="Search...."
android:inputType="textCapCharacters" />
<ImageButton
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_menu_search" />
</RelativeLayout>
But, I would suggest use ActionBar for the search box, it would look neat and easier as well. For search box using ActionBar, you may refer the following link:
http://javapapers.com/android/android-searchview-action-bar-tutorial/