我有一个项目,我使用Android支持库将ActionBar包含在3.0之前的设备中。
我的项目中也有Tabs。标签为Fragments
。这样,我从支持库中扩展了类android.support.v4.app.Fragment
中的每个Tab。
但是,我对3.0之前的设备有问题。没有显示操作栏。所以,也没有标签。
我找不到解决方案......
所以我的“主要活动”(使用标签处理ActionBar)看起来像:
public class Hauptmenue_extended extends ActionBarActivity implements
OnClickListener {
actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tabB = actionBar.newTab();
tabB.setText("Home");
tabB.setIcon(R.drawable.icon_home);
tabB.setTabListener(new TabListener<Startmenue_activity>(this, "Start",
Startmenue_activity.class));
actionBar.addTab(tabB);
Tab tabA = actionBar.newTab();
tabA.setText("");
tabA.setIcon(R.drawable.icon_nachrichten_sel);
tabA.setTabListener(new TabListener<Nachrichten_activity>(this,
"Nachrichten", Nachrichten_activity.class));
actionBar.addTab(tabA);
Tab tabC = actionBar.newTab();
tabC.setText("");
tabC.setIcon(R.drawable.icon_favoriten);
tabC.setTabListener(new TabListener<Favoriten_activity>(this,
"Favoriten", Favoriten_activity.class));
actionBar.addTab(tabC);
我的TabListener看起来像这样:
public static class TabListener<T extends Fragment> implements
ActionBar.TabListener {
private final FragmentActivity myActivity;
private final String myTag;
private final Class<T> myClass;
public TabListener(FragmentActivity activity, String tag, Class<T> cls) {
myActivity = activity;
myTag = tag;
myClass = cls;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Fragment myFragment = myActivity.getSupportFragmentManager()
.findFragmentByTag(myTag);
// Check if the fragment is already initialized
if (myFragment == null) {
// If not, instantiate and add it to the activity
myFragment = Fragment
.instantiate(myActivity, myClass.getName());
ft.add(android.R.id.content, myFragment, myTag);
} else {
// If it exists, simply attach it in order to show it
ft.attach(myFragment);
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
Fragment myFragment = myActivity.getSupportFragmentManager()
.findFragmentByTag(myTag);
if (myFragment != null) {
// Detach the fragment, because another one is being attached
ft.detach(myFragment);
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
每个Fragment或Tab都是这样的:
public class Nachrichten_activity extends Fragment implements
OnChildClickListener, OnClickListener { ...
有没有人有想法? :)
答案 0 :(得分:0)
一些指针,无法确定什么能解决您的问题