Android禁用PageTabStrip

时间:2016-03-07 12:40:54

标签: android

我试图禁用标签在标签之间切换,我使用下面的代码。但那不起作用:

public class CustomPagerTabStrip extends PagerTabStrip {

    private boolean isTabSwitchEnabled;

    public CustomPagerTabStrip(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.isTabSwitchEnabled = true;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        System.out.println("ENable?? "+isTabSwitchEnabled); // it prints out false or true based on what I have set
        if (this.isTabSwitchEnabled) {
            return super.onInterceptTouchEvent(event);
        } else {
            return true;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (this.isTabSwitchEnabled) {
            return super.onTouchEvent(event);
        }
        return false;
    }

    public void setTabSwitchEnabled(boolean isSwipeEnabled) {
        this.isTabSwitchEnabled = isSwipeEnabled;
    }
}

1 个答案:

答案 0 :(得分:0)

您可以通过此链接Disable PageTabStrip