+
+ // Remove the formatting from `urlTextBar` when the user is editing the text.
+ urlTextBox.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus) { // The user is editing `urlTextBox`.
+ // Remove the formatting.
+ urlTextBox.getText().removeSpan(redColorSpan);
+ urlTextBox.getText().removeSpan(boldStyleSpan);
+ } else { // The user has stopped editing `urlTextBox`.
+ // Highlight connections that are not encrypted.
+ if (urlTextBox.getText().toString().startsWith("http://")) {
+ urlTextBox.getText().setSpan(redColorSpan, 0, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ urlTextBox.getText().setSpan(boldStyleSpan, 0, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+ }
+ }
+ });
+
+ // Set the `Go` button on the keyboard to load the URL in `urlTextBox`.