尝试在我的活动中将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"); } };
3 回答
慕运维8079593
TA贡献1876条经验 获得超5个赞
切换到v21支持库时,我的发行版本中可能出现了类似的内容,但调试版本中却没有。原来是一个混淆问题,并将此行添加到我的proguard-rules.txt文件中可以解决此问题:
-keep class android.support.v7.widget.SearchView { *; }
- 3 回答
- 0 关注
- 395 浏览
添加回答
举报
0/150
提交
取消