我想在我的操作栏中显示一些菜单,并且需要在我的应用程序 Activity 中包含操作栏,但我正在使用 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">
关于java - 列表 Activity 中的操作栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33331955/