Android 如何让SwipeRefreshLayout在操作栏中设置文本

Android 如何让SwipeRefreshLayout在操作栏中设置文本,android,android-actionbar,swiperefreshlayout,Android,Android Actionbar,Swiperefreshlayout,当向下滑动以刷新手势出现时,查看PlayNewsstand、QuidCo、OneDrive和YahooMail等应用程序时,操作栏的内容会更改,以指示向下滑动导致刷新。然而,GMail并不更新操作栏的内容,只是依靠progressBar来指示刷新 使用新的SwipeRefreshLayout,如何更新ActionBar内容,使其像PlayNewsstand这样的应用程序 我见过很多关于Chris Banes的ActionBar PulLToRefresh的参考资料,它支持更新ActionBar,

当向下滑动以刷新手势出现时,查看PlayNewsstand、QuidCo、OneDrive和YahooMail等应用程序时,操作栏的内容会更改,以指示向下滑动导致刷新。然而,GMail并不更新操作栏的内容,只是依靠progressBar来指示刷新

使用新的SwipeRefreshLayout,如何更新ActionBar内容,使其像PlayNewsstand这样的应用程序


我见过很多关于Chris Banes的ActionBar PulLToRefresh的参考资料,它支持更新ActionBar,但这是在SwiperFreshLayout之前编写的,因此不是如何让wipeRefreshLayout更新ActionBar文本的示例

swipeLayout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_MOVE){
                Log.i("INFO", "MOVE");
                getActivity().getActionBar().setTitle("Swipe to refresh");
                getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
                getActivity().getActionBar().setCustomView(R.layout.custom_title);
                getActivity().getActionBar().setDisplayUseLogoEnabled(false);
            }
            return false;
        }
    });
自定义_title.xml-将文本居中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="my Title"
    android:id="@+id/mytext"
    android:textSize="18sp" />
</LinearLayout>


在onRefresh结束时或不再收听触摸时,将标题和徽标设置回原位。

太棒了,谢谢。如果我想让actionbar只包含我的文本,我必须隐藏一些操作栏项目,但这给了我一个极好的起点,谢谢。@SarahMaslin,如果它解决了您的问题,请将其标记为正确答案!:)@user2855036,在更改actionbar属性之前,是否有任何方法可以方便地保存它,然后在刷新完成后,我可以将actionbar设置回旧的属性。@HanHe只需将属性保存在局部变量中即可