搜索查看的EditText总是空 [英] SearchView edittext is always null
本文介绍了搜索查看的EditText总是空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我总是这样做,当TextView的为空:
I always get that textView is null when doing this:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat
.getActionView(searchItem);
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
}
谁知道为什么?
Anyone know why?
推荐答案
我使用appcompat V7的操作栏,我的solusion是:
I'm using action bar of appcompat v7 and my solusion is:
TextView searchText = (TextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
希望这有助于。
Hope this help.
这篇关于搜索查看的EditText总是空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文