Loading core/java/android/widget/SearchView.java +21 −7 Original line number Diff line number Diff line Loading @@ -214,6 +214,8 @@ public class SearchView extends LinearLayout { } }); boolean focusable = true; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_maxWidth, -1); Loading @@ -226,6 +228,11 @@ public class SearchView extends LinearLayout { } a.recycle(); a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); focusable = a.getBoolean(R.styleable.View_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Loading Loading @@ -259,10 +266,18 @@ public class SearchView extends LinearLayout { /** @hide */ @Override public boolean requestFocus(int direction, Rect previouslyFocusedRect) { if (mClearingFocus || isIconified()) return false; // Don't accept focus if in the middle of clearing focus if (mClearingFocus) return false; // Check if SearchView is focusable. if (!isFocusable()) return false; // If it is not iconified, then give the focus to the text field if (!isIconified()) { boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect); if (result) updateViewsVisibility(mIconifiedByDefault); if (result) updateViewsVisibility(false); return result; } else { return super.requestFocus(direction, previouslyFocusedRect); } } /** @hide */ Loading Loading @@ -527,7 +542,6 @@ public class SearchView extends LinearLayout { updateCloseButton(); updateVoiceButton(!hasText); updateSubmitArea(); requestLayout(); } private boolean hasVoiceSearch() { Loading Loading @@ -903,8 +917,8 @@ public class SearchView extends LinearLayout { } private void onSearchClicked() { mQueryTextView.requestFocus(); updateViewsVisibility(false); mQueryTextView.requestFocus(); setImeVisibility(true); if (mOnSearchClickListener != null) { mOnSearchClickListener.onClick(this); Loading core/res/res/layout/search_view.xml +3 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,7 @@ android:layout_gravity="center_vertical" android:background="?android:attr/selectableItemBackground" android:src="?android:attr/searchViewCloseIcon" android:focusable="true" /> </LinearLayout> Loading @@ -127,6 +128,7 @@ android:background="?android:attr/selectableItemBackground" android:src="?android:attr/searchViewGoIcon" android:visibility="gone" android:focusable="true" /> <ImageView Loading @@ -139,6 +141,7 @@ android:src="?android:attr/searchViewVoiceIcon" android:background="?android:attr/selectableItemBackground" android:visibility="gone" android:focusable="true" /> </LinearLayout> </LinearLayout> Loading
core/java/android/widget/SearchView.java +21 −7 Original line number Diff line number Diff line Loading @@ -214,6 +214,8 @@ public class SearchView extends LinearLayout { } }); boolean focusable = true; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_maxWidth, -1); Loading @@ -226,6 +228,11 @@ public class SearchView extends LinearLayout { } a.recycle(); a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); focusable = a.getBoolean(R.styleable.View_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Loading Loading @@ -259,10 +266,18 @@ public class SearchView extends LinearLayout { /** @hide */ @Override public boolean requestFocus(int direction, Rect previouslyFocusedRect) { if (mClearingFocus || isIconified()) return false; // Don't accept focus if in the middle of clearing focus if (mClearingFocus) return false; // Check if SearchView is focusable. if (!isFocusable()) return false; // If it is not iconified, then give the focus to the text field if (!isIconified()) { boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect); if (result) updateViewsVisibility(mIconifiedByDefault); if (result) updateViewsVisibility(false); return result; } else { return super.requestFocus(direction, previouslyFocusedRect); } } /** @hide */ Loading Loading @@ -527,7 +542,6 @@ public class SearchView extends LinearLayout { updateCloseButton(); updateVoiceButton(!hasText); updateSubmitArea(); requestLayout(); } private boolean hasVoiceSearch() { Loading Loading @@ -903,8 +917,8 @@ public class SearchView extends LinearLayout { } private void onSearchClicked() { mQueryTextView.requestFocus(); updateViewsVisibility(false); mQueryTextView.requestFocus(); setImeVisibility(true); if (mOnSearchClickListener != null) { mOnSearchClickListener.onClick(this); Loading
core/res/res/layout/search_view.xml +3 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,7 @@ android:layout_gravity="center_vertical" android:background="?android:attr/selectableItemBackground" android:src="?android:attr/searchViewCloseIcon" android:focusable="true" /> </LinearLayout> Loading @@ -127,6 +128,7 @@ android:background="?android:attr/selectableItemBackground" android:src="?android:attr/searchViewGoIcon" android:visibility="gone" android:focusable="true" /> <ImageView Loading @@ -139,6 +141,7 @@ android:src="?android:attr/searchViewVoiceIcon" android:background="?android:attr/selectableItemBackground" android:visibility="gone" android:focusable="true" /> </LinearLayout> </LinearLayout>