1

我很难找到我理解的使用 ActionBarSherlock 的示例。我可以实现TabNavigation.java下载附带的示例。我不确定如何扩展此示例以触发新活动,但仍保持选项卡显示。这是我实现的示例:

package com.actionbarsherlock.sample.demos;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;

public class TabNavigation extends SherlockActivity implements ActionBar.TabListener {
    private TextView mSelected;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setTheme(SampleList.THEME); //Used for theme switching in samples
        super.onCreate(savedInstanceState);

        setContentView(R.layout.tab_navigation);
        mSelected = (TextView)findViewById(R.id.text);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 1; i <= 3; i++) {
            ActionBar.Tab tab = getSupportActionBar().newTab();
            tab.setText("Tab " + i);
            tab.setTabListener(this);
            getSupportActionBar().addTab(tab);
        }
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction transaction) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction transaction) {
        mSelected.setText("Selected: " + tab.getText());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
    }
}

我相信我需要创建一个新的“Listener”类并将其传递给该.setTabListener()方法。我想坚持使用活动(而不是片段),因为我有一个非常复杂的 ORMLite 实现,我还不确定如何将 ORMLite 与片段一起使用。

我想添加一个标记为“配置文件”的新选项卡,它会触发ProfileActivity.class.

提前致谢!

4

2 回答 2

0

I guess that TabListener is supposed to work with Fragments and FragmentTransaction. You will have to move your code from ProfileActivity to a new ProfileFragment class and add it with the FragmentTransaction you receive by the listener.

I would suggest you to add ViewPagerIndicator library on your project, just like this answer. A ViewPager is just like tabs plus the swype movement to navigate between them.

于 2012-10-22T17:02:38.903 回答
0

听起来我没有找到我正在寻找的示例的原因是因为您不能持久地使用操作栏和活动。评论或更好的答案将不胜感激。:)

于 2012-10-22T16:17:00.003 回答