5
我想在Google地圖API V2中使用ActionBarSherlock。我已閱讀here的解決方案。 但當致以主ActionBarSherlock類,它缺少了這麼多lib中menthod(如:findViewById,getSupportActionBar ..)使用ActionBarSherlock和谷歌地圖API V2
這是我ActionBarSherlock
public class FeatureToggles extends SherlockMapFragment {
private static final Random RANDOM = new Random();
private int items = 0;
@Override
public boolean onCreateOptionsMenu(Menu menu){
for(int i = 0; i < items; i++) {
menu.add("Text").setIcon(R.drawable.ic_title_share_default).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
return super.onCreateOptionsMenu(menu);
}
@Override
public void onCreate(Bundle savedInstanceState){
setTheme(R.style.Theme_Sherlock); // Used for theme switching in samples
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.feature_toggles);
setSupportProgressBarIndeterminateVisibility(false);
setSupportProgressBarVisibility(false);
getSupportActionBar().setCustomView(R.layout.custom_view);
getSupportActionBar().setDisplayShowCustomEnabled(false);
Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> listAdapter = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
listAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(listAdapter, null);
// if (savedInstanceState == null) {
// // Do first time initialization -- add initial fragment.
// Fragment newFragment = CountingFragment.newInstance(mStackLevel);
// FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
// ft.add(R.id.simple_fragment, newFragment).commit();
// } else {
// mStackLevel = savedInstanceState.getInt("level");
// }
//
// findViewById(R.id.new_fragment).setOnClickListener(new View.OnClickListener() {
// public void onClick(View v){
// addFragmentToStack();
// }
// });
findViewById(R.id.btnMap).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Intent i = new Intent(getApplicationContext(), GoogleActivityV2.class);
startActivity(i);
}
});
findViewById(R.id.display_progress_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
setSupportProgressBarVisibility(true);
setSupportProgressBarIndeterminateVisibility(false);
setSupportProgress(RANDOM.nextInt(8000) + 10);
}
});
findViewById(R.id.display_progress_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
setSupportProgressBarVisibility(false);
}
});
findViewById(R.id.display_iprogress_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
// Hack to hide the regular progress bar
setSupportProgress(Window.PROGRESS_END);
setSupportProgressBarIndeterminateVisibility(true);
}
});
findViewById(R.id.display_iprogress_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
setSupportProgressBarIndeterminateVisibility(false);
}
});
findViewById(R.id.display_items_clear).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
items = 0;
invalidateOptionsMenu();
}
});
findViewById(R.id.display_items_add).setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
items += 1;
invalidateOptionsMenu();
}
});
findViewById(R.id.display_subtitle_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setSubtitle("The quick brown fox jumps over the lazy dog.");
}
});
findViewById(R.id.display_subtitle_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setSubtitle(null);
}
});
findViewById(R.id.display_title_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayShowTitleEnabled(true);
}
});
findViewById(R.id.display_title_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
});
findViewById(R.id.display_custom_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayShowCustomEnabled(true);
}
});
findViewById(R.id.display_custom_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayShowCustomEnabled(false);
}
});
findViewById(R.id.navigation_standard).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
});
findViewById(R.id.navigation_list).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
}
});
findViewById(R.id.navigation_tabs).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
});
findViewById(R.id.display_home_as_up_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
});
findViewById(R.id.display_home_as_up_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
});
findViewById(R.id.display_logo_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayUseLogoEnabled(true);
}
});
findViewById(R.id.display_logo_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayUseLogoEnabled(false);
}
});
findViewById(R.id.display_home_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
});
findViewById(R.id.display_home_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().setDisplayShowHomeEnabled(false);
}
});
findViewById(R.id.display_actionbar_show).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().show();
}
});
findViewById(R.id.display_actionbar_hide).setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
getSupportActionBar().hide();
}
});
}
public void onTabSelected(Tab tab, FragmentTransaction transaction){
}
public void onTabUnselected(Tab tab, FragmentTransaction transaction){
}
public void onTabReselected(Tab tab, FragmentTransaction transaction){
}
}
更好的路線可能是擴展SherlockFragmentActivity並以編程方式創建您的地圖。查看Google Play服務地圖示例附帶的ProgrammaticDemoActivity示例。這是我如何使用地圖api v2與actionbarsherlock。 – 2013-05-19 04:48:40
@sliver_man謝謝你的回覆,我會試試:) – Dolphin 2013-05-19 05:25:30
@Dolphin請問silver_man的方法適合你嗎? – 2013-06-11 21:22:47