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
私のアプリからのいくつかのコード:
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);
}
スタイル.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;
}
}