Skip to content

Commit

Permalink
Add setCardViewElevation() and addTextChangedListener()
Browse files Browse the repository at this point in the history
  • Loading branch information
mancj committed Dec 12, 2016
1 parent 28fbf4d commit c199044
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .idea/encodings.xml → .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion app/src/main/java/com/mancj/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -33,8 +35,24 @@ protected void onCreate(Bundle savedInstanceState) {
searchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
searchBar.setOnSearchActionListener(this);
searchBar.inflateMenu(R.menu.main);
searchBar.setText("Привет мир");
searchBar.setText("Hello World!");
Log.d("LOG_TAG", getClass().getSimpleName() + ": text " + searchBar.getText());
searchBar.setCardViewElevation(10);
searchBar.addTextChangeListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Log.d("LOG_TAG", getClass().getSimpleName() + " text changed " + searchBar.getText());
}

@Override
public void afterTextChanged(Editable editable) {
Log.d("LOG_TAG", getClass().getSimpleName() + " after text changed " + searchBar.getText());
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.KeyEvent;
Expand Down Expand Up @@ -380,6 +382,23 @@ public String getText(){
return searchEdit.getText().toString();
}

/**
* Set CardView elevation
* @param elevation
*/
public void setCardViewElevation(int elevation){
CardView cardView = (CardView) findViewById(R.id.mt_container);
cardView.setCardElevation(elevation);
}

/**
* Add text watcher to searchbar's EditText
* @param textWatcher
*/
public void addTextChangeListener(TextWatcher textWatcher){
searchEdit.addTextChangedListener(textWatcher);
}

private boolean listenerExists(){
return onSearchActionListener != null;
}
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/layout/searchbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:id="@+id/mt_container"
app:cardElevation="4dp"
app:cardBackgroundColor="@android:color/white"
android:layout_margin="8dp"
Expand Down

0 comments on commit c199044

Please sign in to comment.