简体   繁体   中英

Material Design ToolBar with ListActivity

I am replacing the ActionBar and integrating the Material Design ToolBar within my app. One of my activity's extends ListActivity .

In the onCreate() method, whenever I try to add the ToolBar , the setSupportActionBar() method is producing an error saying it cannot be resolved.

    @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");
    }

What is the best solution to this problem?

You wrote that your activity extends ListActivity but sadly ListActivity doesn't implement setSupportActionBar . You have to base your activity on AppCompatActivity .

You'll say "but hey, but I really need ListActivity as I've ListView in my Activity" -- consider using RecyclerView as well. I'd say that ListView is a dead end now -- one should port code to RecyclerViews

And as a help, two sample projects showing all new features of Material Design

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM