+ final ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ // Remove the title from the action bar.
+ actionBar.setDisplayShowTitleEnabled(false);
+
+ // Add the custom app_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar.
+ actionBar.setCustomView(R.layout.app_bar);
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+
+ // Initialize the variables for favoriteIcon, urlTextBox, and progressBar
+ favoriteIcon = (ImageView) actionBar.getCustomView().findViewById(R.id.favoriteIcon);
+ urlTextBox = (EditText) actionBar.getCustomView().findViewById(R.id.urlTextBox);
+ progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar);
+
+ //actionBar.setHideOnContentScrollEnabled(true);
+ }
+
+ // Implement swipe down to refresh.
+ swipeToRefresh.setColorSchemeColors(0xFF0097FF);
+ swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+ @Override
+ public void onRefresh() {
+ mainWebView.loadUrl(formattedUrlString);
+ }
+ });
+
+ // Only enable swipeToRefresh if is mainWebView is scrolled to the top.
+ mainWebView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
+ @Override
+ public void onScrollChanged() {
+ if (mainWebView.getScrollY() == 0) {
+ swipeToRefresh.setEnabled(true);
+ } else {
+ swipeToRefresh.setEnabled(false);
+ }
+ }
+ });
+