【问题标题】:Material Design ToolBar with ListActivity带有 ListActivity 的材料设计工具栏
【发布时间】:2015-08-09 13:28:18
【问题描述】:

我正在替换 ActionBar 并将 Material Design ToolBar 集成到我的应用程序中。我的一项活动扩展了ListActivity

onCreate() 方法中,每当我尝试添加ToolBar 时,setSupportActionBar() 方法都会产生错误,指出无法解析。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_route_recipients);

        // Attaching the toolbar layout to the toolbar object
        toolbar = (Toolbar) findViewById(R.id.tool_bar);
        // Setting toolbar as the ActionBar with setSupportActionBar() call
        setSupportActionBar(toolbar);

        // get the default list view associated with this activity
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);  // we can now check and uncheck multiple friends

        // get the array of LatLng points passed in from the map intent
        markerPoints = getIntent().getParcelableArrayListExtra("markerPoints");
    }

这个问题的最佳解决方案是什么?

【问题讨论】:

  • 您遇到了什么错误?

标签: java android android-studio material-design android-toolbar


【解决方案1】:

您写道您的活动扩展了ListActivity,但遗憾的是ListActivity 没有实现setSupportActionBar。您的活动必须基于AppCompatActivity

你会说“但是,嘿,但我真的需要ListActivity,因为我的活动中有ListView”——也可以考虑使用RecyclerView。我想说ListView 现在是死路一条——应该将代码移植到RecyclerViews

作为帮助,两个示例项目展示了 Material Design 的所有新功能

【讨论】:

  • 谢谢@pelotasplus ...我会尝试用 RecyclerView 替换 ListView 并看看效果如何...
猜你喜欢
  • 1970-01-01
  • 2017-09-23
  • 2015-03-02
  • 1970-01-01
  • 2019-03-06
  • 2017-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多