Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

android - Adding actionbar to listactivity

Hello so I created a list and I want to add action bar. I am quite new to android so I would like to know how to add action bar while using ListActivity. Any help will be appreciated. Thanks My code:

     public class MainActivity extends ListActivity {

     ArrayList<Item> items = new ArrayList<Item>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        items.add(new SectionItem("2x2 Matrices"));
        items.add(new EntryItem("Adding 2 Matrices"));
        items.add(new EntryItem("Subtracting 2 Matrices"));
        items.add(new EntryItem("Multiplying 2 Matrices"));
        items.add(new EntryItem("Multiplying by a constant"));
        items.add(new EntryItem("Dividing 2 Matrices"));
        items.add(new EntryItem("Negative of a Matrix"));
        items.add(new EntryItem("Inverse of a Matrix"));
        items.add(new EntryItem("Determinant of a Matrix"));

        /*Section2*/
        items.add(new SectionItem("3x3 Matrices"));
        items.add(new EntryItem("Item 4"));
        items.add(new EntryItem("Item 5"));
        items.add(new EntryItem("Item 6"));
        items.add(new EntryItem("Item 7"));
        /*Section3*/
        items.add(new SectionItem("Category 3"));
        items.add(new EntryItem("Item 8"));
        items.add(new EntryItem("Item 9"));
        items.add(new EntryItem("Item 10"));
        items.add(new EntryItem("Item 11"));
        items.add(new EntryItem("Item 12"));

        EntryAdapter adapter = new EntryAdapter(this, items);

        setListAdapter(adapter);
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First- Make sure your Android minimum API-14 or later.

Then, add android:theme="@android:style/Theme.Holo.Light.DarkActionBar" under your ListView_Activity in AndroidManifest.xml class.

Example

        <activity android:name=".Your_ListView_Activity"
                  android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
                  android:label="ListView_Activity_Label">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...