按照本指南,http://wptrafficanalyzer.in/blog/adding-drop-down-navigation-to-action-bar-in-android/
我能够添加我的下拉导航栏。点击事件和一切功能。现在,我该如何做到这一点,一旦选择了一个选项,它就会导航到具有自己布局和不同功能的不同屏幕。
任何帮助都会很棒,在此先感谢!
编辑:这就是我所拥有的。我的应用程序运行了大约一毫秒,我可以看到“Hello World”,然后它崩溃了。顺便说一句,我正在使用 Sherlock,如果这很重要的话。
package com.poe.statcalc;
import com.actionbarsherlock.app.SherlockActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
public class MainActivity extends SherlockActivity {
/** An array of strings to populate dropdown list */
String[] actions = new String[] {
"Bookmark",
"Subscribe",
"Share",
"Something"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** Create an array adapter to populate dropdownlist */
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), R.layout.sherlock_spinner_item, actions);
/** Enabling dropdown list navigation for the action bar */
getSupportActionBar().setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);
/** Defining Navigation listener */
ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
switch(itemPosition) {
case 0:
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i);
break;
case 1:
//...
break;
}
return false;
}
};
/** Setting dropdown items and item navigation listener for the actionbar */
getSupportActionBar().setListNavigationCallbacks(adapter, navigationListener);
adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
}
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
}