- // Update the URL in urlTextBox. It is necessary to do this after the page finishes loading to get the final URL, which can change during load.
- formattedUrlString = mainWebView.getUrl();
- urlTextBox.setText(formattedUrlString);
+ // Set the favorite icon if it changes.
+ @Override
+ public void onReceivedIcon(WebView view, Bitmap icon) {
+ favoriteIcon.setImageBitmap(icon);
+ }
+ });
+
+ // Set the "go" button on the keyboard to load the URL.
+ urlTextBox.setOnKeyListener(new View.OnKeyListener() {
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+
+ // If the event is a key-down event on the "enter" button, load the URL.
+ if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
+ (keyCode == KeyEvent.KEYCODE_ENTER)) {
+ // Load the URL into the mainWebView and consume the event.
+ try {
+ loadUrlFromTextBox(mainWebView);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ // If the enter key was pressed, consume the event.
+ return true;