1

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

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

我已经看到很多对 Chris Banes 的 ActionBar-PulLToRefresh 的引用,它支持更新 ActionBar,但这是在 SwipeRefreshLayout 之前编写的,因此不是如何获取wipeRefreshLayout 以更新 ActionBar 文本的示例

4

1 回答 1

4

你可以做这样的事情

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

custom_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 结束或不再听触摸时,将标题和徽标设置回来。

于 2014-08-18T19:53:51.980 回答