当向下滑动到刷新手势时,查看PlayNewsstand,QuidCo,OneDrive和YahooMail等应用程序时,操作栏的内容会发生变化,以指示向下滑动导致刷新。但是,GMail不会更新操作栏内容,只是依赖progressBar来指示刷新。
使用新的SwipeRefreshLayout如何更新ActionBar内容以像PlayNewsstand这样的应用程序。
我已经看到很多对Chris Banes的ActionBar-PulLToRefresh的引用,它支持ActionBar的更新,但这是在SwipeRefreshLayout之前编写的,因此不是如何让wipeRefreshLayout更新ActionBar文本的示例
答案 0 :(得分:3)
你可以做这样的事情
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结束时或者当不再听触摸时,将标题和徽标重新设置。