当前位置: 代码迷 >> Android >> ListActivity中的操作栏
  详细解决方案

ListActivity中的操作栏

热度:41   发布时间:2023-08-04 12:10:36.0

我想在操作栏中显示一些菜单,并且需要在应用程序活动中包含操作栏,但是我正在使用Listactivity

public class MainActivity extends ListActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MyList.getInstance().getReminders();
    list();
    startService(new Intent(getApplicationContext(), locser.class));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem menu1 = menu.add(0, 1, 0, "Start Service");
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == 1) {
        startService(new Intent(getApplicationContext(), locser.class));
    }
    return super.onOptionsItemSelected(item);
}
void list()
{
    setListAdapter(new listadapter(this, R.layout.reminder_list_layout, MyList.getInstance().getReminders()));
    reminders rem1=new reminders();
    rem1.address="hello";
    rem1.name="je";
    MyList.getInstance().getReminders().add(rem1);
}

如何添加动作栏?

首先,请确保您的Android最低API-14或更高版本,然后添加android:theme="@android:style/Theme.Holo.Light.DarkActionBar"

在AndroidManifest.xml类的ListView_Activity下,输入以下内容:

 <activity android:name=".Your_ListView_Activity"
              android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
              android:label="ListView_Activity_Label">
  相关解决方案