当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Actionbar & tabsadapter: can I long press a tab?

问题描述:

I'm using the actionbar with a tabsadapter. I'd like something to happen when the user long presses on a tab. I've been looking around for ways to add a longpresslistener to the tab, but I haven't found anything. Does anyone know if this is possible?

THANK YOU!

网友答案:

I never found a way to long press a tab. Instead, I overrided onTabReselected. When a user selects a tab, the fragment for that tab is displayed. When the user clicks the tab a second time, a menu appears. It works well.

网友答案:

I use this workaround help method. Long press cannot be set directly but this works.

Basically it is getting tab View via custom view and setting long click listener on it.

public static void setTabLongClickListener(Context context, ActionBar.Tab tab, View.OnLongClickListener longClickListener)
    {
        //get previous view to ensure correct state after setting long click listener
        View previousCustomView = tab.getCustomView();

        //some view to get parent tab view
        View view = new View(context);
        tab.setCustomView(view);
        ((View)view.getParent()).setOnLongClickListener(longClickListener);

        //return back removed custom view
        tab.setCustomView(previousCustomView);
    }

Tested on normal ActionBar, Support AppCompat and ActionBarSherlock.

分享给朋友:
您可能感兴趣的文章:
随机阅读: