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);
    }

}
4

1 回答 1

1

Set setDisplayShowHomeEnabled(true). This will do.

于 2013-09-01T03:17:28.703 回答