ComponentParentpublic class SearchBar extends DirectionalLayout
The search results are displayed in a list. If no match is found, the result is empty. By default, the search component is an icon.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
SearchBar.FoldListener |
Provides callbacks to be invoked when the user closes the search bar.
|
static interface |
SearchBar.QueryListener |
Provides callbacks to be invoked when the query text is changed by the user or when the user submits the query.
|
Component.BindStateChangedListener, Component.CanAcceptScrollListener, Component.ClickedListener, Component.ComponentStateChangedListener, Component.ContourRefreshedListener, Component.DefSpeechEventListener, Component.DoubleClickedListener, Component.DragFeedbackProvider, Component.DraggedListener, Component.DrawTask, Component.EditEventListener, Component.EstimateSizeListener, Component.EstimateSpec, Component.FadeEffectEnum, Component.FocusChangedListener, Component.ForwardHoverListener, Component.ForwardTouchListener, Component.GestureType, Component.HoverEventListener, Component.KeyEventListener, Component.LayoutDirection, Component.LayoutRefreshedListener, Component.LongClickedListener, Component.MeasureSpec, Component.MouseEventListener, Component.MousePointerStyleListener, Component.OnDragListener, Component.RotationEventListener, Component.ScaledListener, Component.ScrolledListener, Component.ShadowDevice, Component.ShadowMode, Component.ShadowSize, Component.SpeechEventListener, Component.TouchEventListener, Component.UnconsumedKeyEventListener, Component.VoiceEventComponentContainer.ArrangeListenerDirectionalLayout.LayoutConfigACCESSIBILITY_ADAPTABLE, ACCESSIBILITY_DISABLE, ACCESSIBILITY_ENABLE, AXIS_X, AXIS_Y, CONTOUR_BACKGROUND, CONTOUR_BORDER, CONTOUR_PADDING_BORDER, DEFAULT_SCALE, DRAG_DOWN, DRAG_HORIZONTAL, DRAG_HORIZONTAL_VERTICAL, DRAG_LEFT, DRAG_RIGHT, DRAG_UP, DRAG_VERTICAL, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED_CLEAR, EVENT_TYPE_COMPONENT_CLICKED, EVENT_TYPE_COMPONENT_FOCUSED, EVENT_TYPE_COMPONENT_LONG_CLICKED, EVENT_TYPE_COMPONENT_SCROLLED, EVENT_TYPE_COMPONENT_SELECTED, EVENT_TYPE_COMPONENT_TEXT_UPDATE, EVENT_TYPE_NOTICE, EVENT_TYPE_NOTIFICATION_STATE_UPDATE, EVENT_TYPE_TOAST_SHOW, EVENT_TYPE_WINDOW_STATE_UPDATE, FOCUS_ADAPTABLE, FOCUS_DISABLE, FOCUS_ENABLE, FOCUS_NEXT, FOCUS_PREVIOUS, FOCUS_SIDE_BOTTOM, FOCUS_SIDE_LEFT, FOCUS_SIDE_RIGHT, FOCUS_SIDE_TOP, HIDE, HORIZONTAL, ID_DEFAULT, INHERITED_MODE, INVISIBLE, mBackgroundElement, mCanvasForTaskOverContent, mCanvasForTaskUnderContent, mComponentParent, mContext, mDrawTaskOverContent, mDrawTaskUnderContent, mEstimateSizeListener, mForegroundElement, mForwardHoverListener, mHoverEventListener, mKeyEventListener, mMouseEventListener, mPosition, mRotationEventListener, mShadowElement, mUnconsumedKeyEventListener, OVAL_MODE, OVAL_SCROLL_BAR_MODE, POSITION_X_INDEX, POSITION_Y_INDEX, RECT_MODE, RECT_SCROLL_BAR_MODE, SCROLL_AUTO_STAGE, SCROLL_IDLE_STAGE, SCROLL_NORMAL_STAGE, UNSPECIFIED_SCROLL_BAR_MODE, VERTICAL, VISIBLEFOCUS_CHILDREN_FIRST, FOCUS_CHILDREN_HIDE, FOCUS_PARENT_FIRST, mArrangeListener| 构造器 | 说明 |
|---|---|
SearchBar(Context context) |
Default constructor used to create a
SearchBar instance by using the default attribute set and style. |
SearchBar(Context context,
AttrSet attrSet) |
A constructor used to create a
SearchBar instance by using specified attribute set and default style
after the XML file is parsed. |
SearchBar(Context context,
AttrSet attrSet,
String styleName) |
A constructor used to create a
SearchBar instance by using specified attribute set and specified style
after the XML file is parsed. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
activateSubmitButton(boolean enabled) |
Specifies whether the submit button must be available if the query is not empty.
|
void |
addComponent(Component childComponent) |
Adds a component to the end of the queue by invoking
ComponentContainer.addComponent(ohos.agp.components.Component,int index) internally. |
Image |
getCloseButton() |
Obtains the close button of this
SearchBar. |
SearchBar.FoldListener |
getFoldListener() |
Obtains the listener for monitoring closure of this
SearchBar. |
boolean |
getIconifiedState() |
Obtains the current state of the search bar.
|
int |
getMaxWidth() |
Obtains the maximum width specified for the search bar.
|
String |
getQuery() |
Obtains the search string in the search bar.
|
String |
getQueryHint() |
Obtains the hint text in the search bar.
|
SearchBar.QueryListener |
getQueryListener() |
Obtains the listener for monitoring the change or submission of a search string in this
SearchBar. |
Image |
getSearchButton() |
Obtains the search button of this
SearchBar. |
Component.ClickedListener |
getSearchClickListener() |
Obtains the listener for the notification sent when the search button is clicked.
|
Image |
getSearchIcon() |
Obtains the search icon of this
SearchBar. |
TextField |
getSearchText() |
Obtains the search text of this
SearchBar. |
Color |
getSearchTextColor() |
Obtains the text color of the search box.
|
Image |
getSubmitButton() |
Obtains the submit button of this
SearchBar. |
int |
getTextSize() |
Obtains the text size of the search bar.
|
boolean |
isSearchButtonEnable() |
Checks whether the submit button is enabled when necessary.
|
void |
setCloseButton(int resId) |
Sets the image resource ID for the close button.
|
void |
setCloseButton(PixelMap pixelMap) |
Sets the image URI for the close button.
|
void |
setFoldListener(SearchBar.FoldListener listener) |
Sets a listener to inform when the user closes the
SearchBar. |
void |
setIconifiedState(boolean state) |
Sets whether to iconify or expand the search bar.
|
void |
setMaxWidth(int maxPixels) |
Sets the maximum width of the search bar, in pixels.
|
void |
setQuery(String query,
boolean submit) |
Sets the search string and search mode.
|
void |
setQueryFocusChangeListener(Component.FocusChangedListener listener) |
Sets a listener to inform when the focus of the query text field changes.
|
void |
setQueryListener(SearchBar.QueryListener listener) |
Sets a listener to inform when the user changes or submits the search string in the search bar.
|
void |
setSearchButton(int resId) |
Sets the image resource ID for the search button.
|
void |
setSearchButton(PixelMap pixelMap) |
Sets the pixelMap for the search button.
|
void |
setSearchClickListener(Component.ClickedListener listener) |
Sets a listener to inform when the search button is pressed.
|
void |
setSearchHint(String searchHint) |
Sets the hint text to display in the search box.
|
void |
setSearchIcon(int resId) |
Sets the image resource ID for the search icon.
|
void |
setSearchIcon(PixelMap pixelMap) |
Sets the pixelMap for the search icon.
|
void |
setSearchTextColor(Color color) |
Sets the text color for the search box.
|
void |
setSubmitButton(int resId) |
Sets the image resource ID for the submit button.
|
void |
setSubmitButton(PixelMap pixelMap) |
Sets the pixelMap for the submit button.
|
void |
setTextSize(int textSize) |
Sets the text size for the search bar.
|
addDrawTask, addDrawTask, addScrolledListener, announceAccessibility, arrange, bindCornerMark, callOnClick, canScroll, clearFocus, createAnimatorProperty, disableFadeEffect, draw, enableCornerMark, enableFadeEffect, enableSaveState, enableScrollBar, estimateSize, executeDoubleClick, executeLongClick, findFocus, findNextFocusableComponent, findRequestNextFocus, getAccessibility, getAccessibilityDescription, getAlpha, getAltitude, getBackgroundElement, getBaseLine, getBottom, getBoundaryFadeEffectBottomRate, getBoundaryFadeEffectLeftRate, getBoundaryFadeEffectRightRate, getBoundaryFadeEffectTopRate, getCenterZoomFactor, getCentralScrollMode, getClickedListener, getClipEnabled, getComponentDescription, getComponentMinSize, getComponentParent, getComponentPosition, getComponentSize, getComponentStateChangedListener, getComponentTreeObserver, getContentEnable, getContentPosition, getContentPositionX, getContentPositionY, getContext, getContour, getContourRefreshedListener, getCornerMark, getDragAcceptAngle, getDraggedListener, getEditEventListener, getEstimatedHeight, getEstimatedWidth, getFadeEffectBoundaryWidth, getFadeEffectColor, getFocusable, getFocusBorderEnable, getFocusBorderPadding, getFocusBorderRadius, getFocusBorderWidth, getForegroundElement, getForegroundGravity, getForwardHoverListener, getForwardTouchListener, getGesturePriority, getHeight, getHorizontalPadding, getHorizontalPosition, getHoverEventListener, getId, getKeyEventListener, getLayoutConfig, getLayoutDirection, getLayoutDirectionResolved, getLayoutRefreshedListener, getLeft, getLocationOnScreen, getMarginBottom, getMarginLeft, getMarginRight, getMargins, getMarginsLeftAndRight, getMarginsTopAndBottom, getMarginTop, getMatrix, getMinHeight, getMinWidth, getMode, getModeResolved, getMouseEventListener, getMousePointerStyleListener, getName, getPadding, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPivot, getPivotX, getPivotY, getResourceManager, getRight, getRotation, getRotationEventListener, getRotationSensitivity, getScale, getScaledListener, getScaleX, getScaleY, getScrollbarBackgroundColor, getScrollbarColor, getScrollbarFadingDelay, getScrollbarFadingDuration, getScrollBarMode, getScrollbarRadius, getScrollbarRoundRect, getScrollbarStartAngle, getScrollbarSweepAngle, getScrollbarThickness, getScrollState, getScrollValue, getSelfVisibleRect, getShadowColor, getSpeechEventListener, getTag, getTop, getTouchEventListener, getTransitionSymbol, getTranslation, getTranslationX, getTranslationY, getTranslationZ, getUserNextFocus, getVerticalPadding, getVerticalPosition, getVisibility, getVisibleRectOnScreen, getWidth, getWindowVisibleRect, hasFocus, hasFocusedEffect, hasOverlaps, hideFocusBorder, invalidate, isBoundaryFadeEffectEnable, isBoundToWindow, isClickable, isClipToContourEnabled, isComponentDisplayed, isEnabled, isFadeEffected, isFocusable, isFocused, isIdentityMatrix, isLongClickOn, isPressed, isRtl, isSaveStateEnabled, isScrollbarFadingOn, isScrollBarOn, isScrollbarOverlapEnabled, isSelected, isSoundEnable, isTouchFocusable, isVibrationEffectEnabled, notifyAccessibility, onAttributeConfigChanged, onRestoreState, onRtlChanged, onSaveState, performScale, playSound, postLayout, refreshContour, release, removeBindStateChangedListener, removeScrolledListener, requestFocus, requestForceForwardTouchEvent, restoreComponentTreeState, saveComponentTreeState, scrollBy, scrollTo, setAccessibility, setAccessibilityDescription, setAlpha, setAltitude, setBackground, setBindStateChangedListener, setBottom, setBoundaryFadeEffectEnable, setCanAcceptScrollListener, setCenterZoomFactor, setCentralScrollMode, setClickable, setClickedListener, setClipEnabled, setClipToContourEnabled, setComponentDescription, setComponentMinSize, setComponentPosition, setComponentPosition, setComponentSize, setComponentStateChangedListener, setContentEnable, setContentPosition, setContentPositionX, setContentPositionY, setContour, setContourRefreshedListener, setDoubleClickedListener, setDragAcceptAngle, setDraggedListener, setEditEventListener, setEnabled, setEstimatedSize, setEstimateSizeListener, setFadeEffectBoundaryWidth, setFadeEffectColor, setFocusable, setFocusBorderEnable, setFocusBorderPadding, setFocusBorderRadius, setFocusBorderRadius, setFocusBorderWidth, setFocusChangedListener, setFocusedEffect, setForeground, setForegroundGravity, setForwardHoverListener, setForwardTouchListener, setGesturePriority, setHeight, setHorizontalPadding, setHorizontalPosition, setHoverEventListener, setId, setKeyEventListener, setLayoutConfig, setLayoutDirection, setLayoutRefreshedListener, setLeft, setLongClickable, setLongClickedListener, setMarginBottom, setMarginLeft, setMarginRight, setMarginsLeftAndRight, setMarginsTopAndBottom, setMarginTop, setMinHeight, setMinWidth, setMode, setMouseEventListener, setMousePointerStyleListener, setName, setOnDragListener, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRelative, setPaddingRight, setPaddingTop, setPivot, setPivot, setPivotX, setPivotY, setPosition, setPositionX, setPositionY, setPressState, setRight, setRotation, setRotationEventListener, setRotationSensitivity, setScale, setScaledListener, setScaleX, setScaleY, setScrollbarBackgroundColor, setScrollbarColor, setScrollbarFadingDelay, setScrollbarFadingDuration, setScrollbarFadingEnabled, setScrollBarMode, setScrollbarOverlapEnabled, setScrollbarRadius, setScrollbarRoundRect, setScrollbarStartAngle, setScrollbarSweepAngle, setScrollbarThickness, setScrolledListener, setSelected, setShadowColor, setShadowStyle, setSoundEnable, setSpeechEventListener, setTag, setTop, setTouchEventListener, setTouchFocusable, setTransitionSymbol, setTranslation, setTranslationX, setTranslationY, setTranslationZ, setUnconsumedKeyEventListener, setUserNextFocus, setVerticalPadding, setVerticalPosition, setVibrationEffectEnabled, setVisibility, setWidth, showFocusBorder, simulateClick, simulateDrag, startDragAndDrop, subscribeVoiceEvents, unsubscribeVoiceEventsaddComponent, addComponent, addComponent, addComponent, dispatchRestoreState, dispatchSaveState, findComponentById, findComponentHolderById, getAutoLayout, getChildCount, getChildIndex, getComponentAt, getComponentTransition, getFocusOrder, getLayoutManager, informConfigurationChanged, isClipToChildBoundsEnabled, isClipToPaddingBoundsEnabled, isTouchEventSplitable, moveChildToFront, onDrag, removeAllComponents, removeComponent, removeComponentAt, removeComponentById, removeComponents, setArrangeListener, setAutoLayout, setAutoLayout, setClipToChildBoundsEnabled, setClipToPaddingBoundsEnabled, setComponentTransition, setFocusOrder, setLayoutManager, setTouchEventSplitablegetComponentParent, postLayoutcreateLayoutConfig, getAlignment, getOrientation, getTotalWeight, isLayoutBaselined, setAlignment, setLayoutBaselined, setOrientation, setTotalWeight, verifyLayoutConfigpublic SearchBar(Context context)
SearchBar instance by using the default attribute set and style.context - Indicates the application context.public SearchBar(Context context, AttrSet attrSet)
SearchBar instance by using specified attribute set and default style
after the XML file is parsed.context - Indicates the application context.attrSet - Indicates the attribute set to be used.public SearchBar(Context context, AttrSet attrSet, String styleName)
SearchBar instance by using specified attribute set and specified style
after the XML file is parsed.context - Indicates the application context.attrSet - Indicates the attribute set to be used.styleName - Indicates the style name to use.public void addComponent(Component childComponent)
ComponentContainer.addComponent(ohos.agp.components.Component,int index) internally.addComponent 在类中 ComponentContainerchildComponent - Indicates the child component to add.public TextField getSearchText()
SearchBar.public Image getSearchButton()
SearchBar.public Image getSearchIcon()
SearchBar.public Image getSubmitButton()
SearchBar.public Image getCloseButton()
SearchBar.public void setTextSize(int textSize)
textSize - Indicates the text size in the search bar.public int getTextSize()
public void setQuery(String query, boolean submit)
query - Indicates the search string.submit - true means to start a search immediately after the search string is updated;
false means to update the search string only, but not to start the search immediately.public String getQuery()
public void setSearchHint(String searchHint)
The hint text is displayed in the search box upon initialization or before any search string is provided by the user.
searchHint - Indicates the hint text to display in the search box.public String getQueryHint()
public void setMaxWidth(int maxPixels)
maxPixels - Indicates the maximum width of the search bar, in pixels.public int getMaxWidth()
0 if the maximum width is not specified.public void setIconifiedState(boolean state)
state - Indicates whether to iconify or expand the search bar. true means to iconify the
search bar, and false means to expand it.public boolean getIconifiedState()
true if the search bar is iconified; returns false if it is expanded.public void setFoldListener(SearchBar.FoldListener listener)
SearchBar.listener - Indicates the listener to call when the user closes the SearchBar.public SearchBar.FoldListener getFoldListener()
SearchBar.public void setQueryListener(SearchBar.QueryListener listener)
listener - Indicates the listener object that receives callbacks when the user changes the search
string or presses the search button in the search bar.public SearchBar.QueryListener getQueryListener()
SearchBar.public void setQueryFocusChangeListener(Component.FocusChangedListener listener)
listener - Indicates the listener to inform of focus changes in the search bar.public void setSearchClickListener(Component.ClickedListener listener)
listener - Indicates the listener to inform when the search button is pressed or the search bar is
programmatically de-iconified.public Component.ClickedListener getSearchClickListener()
public void activateSubmitButton(boolean enabled)
enabled - Indicates the state of the submit button. true means to display the submit button;
false means to hide it.public boolean isSearchButtonEnable()
true if the submit button is enabled automatically when necessary; returns false
otherwise.public void setSearchButton(PixelMap pixelMap)
pixelMap - Indicates the PixelMap.public void setSearchIcon(PixelMap pixelMap)
pixelMap - Indicates the PixelMap.public void setCloseButton(PixelMap pixelMap)
pixelMap - Indicates the PixelMap.public void setSubmitButton(PixelMap pixelMap)
pixelMap - Indicates the PixelMap.public void setSearchButton(int resId)
resId - Indicates the image resource ID to set.public void setSearchIcon(int resId)
resId - Indicates the image resource ID to set.public void setSubmitButton(int resId)
resId - Indicates the image resource ID to set.public void setCloseButton(int resId)
resId - Indicates the image resource ID to set.public void setSearchTextColor(Color color)
color - Indicates the text color.public Color getSearchTextColor()