0
如何將標籤放置在操作欄下方?謝謝。 對不起,我忘了粘貼我的代碼。我在這一行做了一些變化:actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
但它還沒有工作。將標籤放在操作欄下方
http://www.imgbox.de/show/img/9nasrIPHg1.png
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
public class ActionBarFragmentsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab TabA = actionbar.newTab().setText("Fragment A");
ActionBar.Tab TabB = actionbar.newTab().setText("Fragment B");
ActionBar.Tab TabC = actionbar.newTab().setText("Fragment C");
Fragment fragmentA = new fragmentA();
Fragment fragmentB = new fragmentB();
Fragment fragmentC = new fragmentC();
TabA.setTabListener(new MyTabsListener(fragmentA));
TabB.setTabListener(new MyTabsListener(fragmentB));
TabC.setTabListener(new MyTabsListener(fragmentC));
actionbar.addTab(TabA);
actionbar.addTab(TabB);
actionbar.addTab(TabC);
}
}
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// wenn das Tab erneut gewählt wird.
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
}
選中此項:http://dj-android.blogspot.in/2013/02/android-adding-actionbar-navigation-tabs.html和http://dj-android.blogspot.in/2013/02/ Android系統的加入,動作條,navigation.html – 2013-04-04 13:03:56