我刚刚在我的 Android 应用程序中实现了 Sherlock 的 ActionBar。
问题是:从图片中可以看出,我在 MainActivity 中加载的 Google Maps API v2 SupportMapFragment 完全被 actionBar 覆盖。我已经做了一些测试:加载一个不同的片段,例如一个简单的 SherlockListFragment,但结果是完全一样的,并且不要设置 setListNavigationCallbacks(因为问题可能是我的自定义 SpinnerAdapter)但 actionBar 总是涵盖所有屏幕,即使里面没有任何文字。
图片: https ://www.dropbox.com/s/y0lnekjttdzv2xa/2012-12-18_14-45-43.png
我的应用程序中的一些代码:
主.java
public class Main extends SherlockFragmentActivity implements ActionBar.OnNavigationListener
{
private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item";
private FragmentMappa fMappa;
private FragmentLinee fLinee;
private FragmentAtmInforma fAtm;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
fMappa = new FragmentMappa();
fLinee = new FragmentLinee();
fAtm = new FragmentAtmInforma();
setContentView(R.layout.activity_main);
int IdFixedHeader = -1;
Utils.ImpostaActionBar(IdFixedHeader, this);
getSupportFragmentManager().addOnBackStackChangedListener(getListener());
getSupportFragmentManager().beginTransaction().replace(R.id.MainContainer, fMappa).commit();
new downloadUtils().execute(0, this, true);
}
实用程序.java
public static void ImpostaActionBar(int IdFixedHeader, SherlockFragmentActivity Act, String StrFixHead) {
// Set up the action bar to show a dropdown list.
ActionBar actionBar = Act.getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayList<VoceListaMenuNav> Voci = new ArrayList<VoceListaMenuNav>();
Voci.add(new VoceListaMenuNav(Act.getString(R.string.title_mappa), R.drawable.btn_show_map));
Voci.add(new VoceListaMenuNav(Act.getString(R.string.title_linee), R.drawable.btn_compass_tilt));
Voci.add(new VoceListaMenuNav(Act.getString(R.string.title_percorso), R.drawable.fer));
Voci.add(new VoceListaMenuNav(Act.getString(R.string.title_preferiti), R.drawable.btn_show_map));
Voci.add(new VoceListaMenuNav(Act.getString(R.string.title_AtmInforma), R.drawable.btn_show_map));
// Set up the dropdown list navigation in the action bar.
actionBar.setListNavigationCallbacks(new AdapterListaMenuNav(Act.getSupportActionBar().getThemedContext(), Voci, IdFixedHeader, StrFixHead), (OnNavigationListener) Act);
actionBar.setSelectedNavigationItem(IdFixedHeader);
}
样式.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<color name="GrigioSemiTrasp">#af000000</color>
<style name="ActionBar" parent="Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
<item name="android:background">@color/GrigioSemiTrasp</item>
</style>
</resources>
我的自定义适配器:
public class AdapterListaMenuNav extends BaseAdapter
{
@Override
public View getView(int arg0, View arg1, ViewGroup parent) {
View rowView = arg1;
if (rowView == null)
{
rowView = inflater.inflate(R.layout.list_item_menu_nav_top, null);
ViewHolderListaGenerica viewHolder = new ViewHolderListaGenerica();
viewHolder.Titolo = (TextView) rowView.findViewById(R.id.ListaMenuNavTitolo);
rowView.setTag(viewHolder);
}
if (FixedHeader == -1)
{
ViewHolderListaGenerica holder = (ViewHolderListaGenerica)rowView.getTag();
VoceListaMenuNav f = LisVoci.get(arg0);
holder.Titolo.setText(f.Titolo);
return rowView;
}
else
{
ViewHolderListaGenerica holder = (ViewHolderListaGenerica)rowView.getTag();
VoceListaMenuNav f = LisVoci.get(FixedHeader);
holder.Titolo.setText(f.Titolo);
return rowView;
}
}
Context Ctx;
ArrayList<VoceListaMenuNav> LisVoci;
LayoutInflater inflater;
int FixedHeader;
public AdapterListaMenuNav(Context Cont, ArrayList<VoceListaMenuNav> ListaVoci, int IdFixedHeader, String StrFxHeader)
{
LisVoci = ListaVoci;
inflater = (LayoutInflater)Cont.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Ctx = Cont;
FixedHeader = IdFixedHeader;
}
@Override
public int getCount() {
return LisVoci.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getDropDownView(int arg0, View arg1, ViewGroup arg2) {
View rowView = arg1;
if (rowView == null)
{
rowView = inflater.inflate(R.layout.list_item_menu_nav, null);
ViewHolderListaGenerica viewHolder = new ViewHolderListaGenerica();
viewHolder.Titolo = (TextView) rowView.findViewById(R.id.ListaMenuNavTitolo);
viewHolder.Immagine = (ImageView) rowView.findViewById(R.id.ListaMenuNavImage);
rowView.setTag(viewHolder);
}
ViewHolderListaGenerica holder = (ViewHolderListaGenerica)rowView.getTag();
VoceListaMenuNav f = LisVoci.get(arg0);
holder.Titolo.setText(f.Titolo);
holder.Immagine.setImageResource(f.IdImage);
return rowView;
}
}