我刚刚在我的Android应用程序中实现了Sherlock的ActionBar。
问题是:正如您从图像中看到的那样,加载在MainActivity中的Google Maps API v2的SupportMapFragment完全被actionBar覆盖。我已经做了一些测试:加载一个不同的片段,例如一个简单的SherlockListFragment,但结果完全相同,并且不要设置setListNavigationCallbacks(因为问题可能是我的自定义SpinnerAdapter)但actionBar总是覆盖所有屏幕,即使没有任何文字。
IMAGE: https://www.dropbox.com/s/y0lnekjttdzv2xa/2012-12-18_14-45-43.png
我的应用中的一些代码:
Main.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);
}
Utils.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);
}
styles.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;
}
}
答案 0 :(得分:0)
我努力找到任何东西,最后可以自己回答。问题来自于ABS风格的继承。正确的代码是:
<style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar">
....
</style>