一、实现获取焦点之后提示语消失
_editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus==true){//获取焦点了
_editText.setHint("");
}else {
_editText.setHint("搜索");
}
}
});
二、修改光标样式
鼠标res右键-> new -> Android resource file
File name: search_edit_background
Resource Type: Drawable
内容为:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid android:color="#fff"/>
<corners android:radius="15dp"/>
<stroke
android:width="1dp"
android:color="#e6e6e6"/>
</shape>
</item>
</layer-list>
三、实现边输入边搜索功能
/*给导航栏中间的搜索框加监听,实现边输入边搜索的功能*/
_editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Log.d("搜索值=", s.toString());
//调用网络请求方法
}
});
网友评论