我有textview如果此textview中有任何文字,我想将搜索按钮添加到操作栏
任何想法如何实现,我添加了如下的监听器
private TextWatcher textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
invalidateOptionsMenu();
}
};
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(seachEditText.getText().toString().length() > 0){
// add the search button to action bar
}
else{
// remove the search button to action bar
}
return super.onPrepareOptionsMenu(menu);
}
如何动态添加删除搜索按钮到操作栏