尝试在我的活动中将SearchView小部件添加到ActionBar时遇到问题-调用getActionView获取我的SearchView对象时,我得到一个空值。
我一直在关注Android开发人员指南,还遇到了大量SO问题以及Internet上的其他一些链接;一切都无济于事。它可能很简单,但我无法弄清楚-在我看来,我的代码与google的代码基本相同(除了更改了一些名称等),但仍然无法正常工作。
任何帮助,将不胜感激。
以下包括代码的相关位。如果有任何不清楚的地方,请让我知道。
活动代码:
private ListView workflowListView;
private DrawerLayout drawerLayout;
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_workflow_list);
workflowListView = (ListView) findViewById(R.id.workflowListView);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ListView) findViewById(R.id.drawer_list);
drawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.drawable.ic_launcher, /* nav drawer icon to replace 'Up' caret */
R.string.app_name, /* "open drawer" description */
R.string.app_name /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
// getActionBar().setTitle("Closed drawer");
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
// getActionBar().setTitle("Open drawer");
}
};