Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Cute library to implement SearchView in a Material Design Approach. *Works from
src="https://developer.android.com/images/brand/en_generic_rgb_wo_60.png" />
</a>

#Native version
Maybe it would be useful to take a look into the new official approach
http://www.materialdoc.com/search-filter/

# Usage
**Add the dependencies to your gradle file:**
```javascript
Expand Down Expand Up @@ -172,52 +176,52 @@ Cute library to implement SearchView in a Material Design Approach. *Works from
# Using AppBarLayout?
It is a little bit tricky but can be achieved using this:
```xml
<RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android
xmlns:app=http://schemas.android.com/apk/res-auto
android:id=@+id/container
android:layout_width=match_parent
android:layout_height=match_parent>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!— Irrelevant stuff —>
<android.support.v4.view.ViewPager
android:id=@+id/viewpager
android:layout_width=match_parent
android:layout_height=match_parent
android:layout_below=@+id/appbarlayout
app:layout_behavior=@string/appbar_scrolling_view_behavior />
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appbarlayout"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<!— Must be last for right layering display —>
<android.support.design.widget.AppBarLayout
android:id=@+id/appbarlayout
android:layout_width=match_parent
android:layout_height=wrap_content
android:background=@color/search_layover_bg>
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/search_layover_bg">

<FrameLayout
android:id=@+id/toolbar_container
android:layout_width=match_parent
android:layout_height=wrap_content>
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id=@+id/toolbar
android:layout_width=match_parent
android:layout_height=?attr/actionBarSize
android:background=@color/theme_primary />
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/theme_primary" />

<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id=@+id/search_view
android:layout_width=match_parent
android:layout_height=wrap_content
android:visibility=gone />
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</FrameLayout>

<android.support.design.widget.TabLayout
android:id=@+id/tabs
android:layout_width=match_parent
android:layout_height=wrap_content
android:background=@color/theme_primary
app:tabGravity=fill
app:tabMode=fixed />
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme_primary"
app:tabGravity="fill"
app:tabMode="fixed" />

</android.support.design.widget.AppBarLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
Expand Down Expand Up @@ -135,6 +136,10 @@ private void initStyle(AttributeSet attrs, int defStyleAttr) {
setSuggestionIcon(a.getDrawable(R.styleable.MaterialSearchView_searchSuggestionIcon));
}

if (a.hasValue(R.styleable.MaterialSearchView_android_inputType)) {
setInputType(a.getInt(R.styleable.MaterialSearchView_android_inputType, EditorInfo.TYPE_NULL));
}

a.recycle();
}
}
Expand Down Expand Up @@ -335,6 +340,10 @@ public void setSuggestionIcon(Drawable drawable) {
suggestionIcon = drawable;
}

public void setInputType(int inputType) {
mSearchSrcTextView.setInputType(inputType);
}

public void setSuggestionBackground(Drawable background) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mSuggestionsListView.setBackground(background);
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<attr name="android:hint" />
<attr name="android:textColor" />
<attr name="android:textColorHint" />
<attr name="android:inputType" />
</declare-styleable>
</resources>
4 changes: 4 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
android:name=".TabActivity"
android:label="@string/title_activity_tab">
</activity>
<activity
android:name=".InputTypeActivity"
android:label="@string/title_activity_input_type">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.miguelcatalan.materialsearchview.sample;

import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import com.miguelcatalan.materialsearchview.MaterialSearchView;
import java.util.ArrayList;

public class InputTypeActivity extends AppCompatActivity {

private MaterialSearchView searchView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input_type);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

searchView = (MaterialSearchView) findViewById(R.id.search_view);
searchView.setVoiceSearch(false);
searchView.setCursorDrawable(R.drawable.custom_cursor);
searchView.setEllipsize(true);
searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
.show();
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
//Do some magic
return false;
}
});

searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
//Do some magic
}

@Override
public void onSearchViewClosed() {
//Do some magic
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);

MenuItem item = menu.findItem(R.id.action_search);
searchView.setMenuItem(item);

return true;
}

@Override
public void onBackPressed() {
if (searchView.isSearchOpen()) {
searchView.closeSearch();
} else {
super.onBackPressed();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (matches != null && matches.size() > 0) {
String searchWrd = matches.get(0);
if (!TextUtils.isEmpty(searchWrd)) {
searchView.setQuery(searchWrd, false);
}
}

return;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Button voiceButton;
private Button stickyButton;
private Button tabButton;
private Button inputTypeButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -29,6 +30,8 @@ protected void onCreate(Bundle savedInstanceState) {
stickyButton.setOnClickListener(this);
tabButton = (Button) findViewById(R.id.button_tab);
tabButton.setOnClickListener(this);
inputTypeButton = (Button) findViewById(R.id.button_input_type);
inputTypeButton.setOnClickListener(this);
}

@Override
Expand All @@ -50,6 +53,9 @@ public void onClick(View view) {
case R.id.button_tab:
intent = new Intent(this, TabActivity.class);
break;
case R.id.button_input_type:
intent = new Intent(this, InputTypeActivity.class);
break;
}
if (intent != null) {
startActivity(intent);
Expand Down
32 changes: 32 additions & 0 deletions sample/src/main/res/layout/activity_input_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Irrelevant stuff -->
<include
layout="@layout/mok_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />

<!-- Must be last for right layering display -->
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/theme_primary" />

<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</FrameLayout>

</FrameLayout>
17 changes: 12 additions & 5 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,45 @@

<Button
android:id="@+id/button_default"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Default"
android:textColor="@color/theme_secondary_text" />

<Button
android:id="@+id/button_themed"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Themed"
android:textColor="@color/theme_secondary_text" />

<Button
android:id="@+id/button_voice"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Voice"
android:textColor="@color/theme_secondary_text" />

<Button
android:id="@+id/button_sticky"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sticky"
android:textColor="@color/theme_secondary_text" />

<Button
android:id="@+id/button_tab"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tabs"
android:textColor="@color/theme_secondary_text" />

<Button
android:id="@+id/button_input_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Input type"
android:textColor="@color/theme_secondary_text" />
</LinearLayout>

</RelativeLayout>
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<string name="title_activity_voice">VoiceActivity</string>
<string name="title_activity_sticky">StickyActivity</string>
<string name="title_activity_tab">TabActivity</string>
<string name="title_activity_input_type">InputTypeActivity</string>

<string name="action_settings">Settings</string>
</resources>