diff options
| author | Amith Yamasani <yamasani@google.com> | 2011-06-23 16:16:05 -0700 |
|---|---|---|
| committer | Amith Yamasani <yamasani@google.com> | 2011-06-23 17:35:32 -0700 |
| commit | 246529891ee289e8393ad4a486db785ef455c778 (patch) | |
| tree | 2fb23529dc1be51ada7d5c213bbc8dc207bcb294 /core/java/android/widget/SearchView.java | |
| parent | 032897470aa5df2400996ffa5d26a937803ea446 (diff) | |
SearchView improvements per design.
- X is visible only if there is text, or we need a way to close a
search field that is iconified by default.
- Search dialog (legacy) has a back button to the left.
- Hitting X on a non-focused search view will bring it into focus
and show the keyboard if necessary.
Change-Id: I5a30bb08adcf84639a922a9e13be1d1562f714e6
Diffstat (limited to 'core/java/android/widget/SearchView.java')
| -rw-r--r-- | core/java/android/widget/SearchView.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index 586ece841fc5..f3bda439fbe8 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -603,7 +603,7 @@ public class SearchView extends LinearLayout { final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText()); // Should we show the close button? It is not shown if there's no focus, // field is not iconified by default and there is no text in it. - final boolean showClose = hasText || mIconifiedByDefault || mQueryTextView.hasFocus(); + final boolean showClose = hasText || mIconifiedByDefault; mCloseButton.setVisibility(showClose ? VISIBLE : INVISIBLE); mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET); } @@ -919,17 +919,22 @@ public class SearchView extends LinearLayout { } private void onCloseClicked() { - if (mOnCloseListener == null || !mOnCloseListener.onClose()) { - CharSequence text = mQueryTextView.getText(); - if (TextUtils.isEmpty(text)) { + CharSequence text = mQueryTextView.getText(); + if (TextUtils.isEmpty(text)) { + if (mIconifiedByDefault) { // query field already empty, hide the keyboard and remove focus clearFocus(); setImeVisibility(false); - } else { - mQueryTextView.setText(""); } + } else { + mQueryTextView.setText(""); + mQueryTextView.requestFocus(); + setImeVisibility(true); + } + + if (mIconifiedByDefault && (mOnCloseListener == null || !mOnCloseListener.onClose())) { updateViewsVisibility(mIconifiedByDefault); - if (mIconifiedByDefault) setImeVisibility(false); + setImeVisibility(false); } } |
