Google 致力于为黑人社区推动种族平等。查看具体举措

TooltipDrawable

public class TooltipDrawable
extends MaterialShapeDrawable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ com.google.android.material.shape.MaterialShapeDrawable
       ↳ com.google.android.material.tooltip.TooltipDrawable


A Tooltip that supports shape theming and draws a pointer on the bottom in the center of the supplied bounds. Additional margin can be applied which will prevent the main bubble of the Tooltip from being drawn too close to the edge of the window.

Note: setRelativeToView(View) should be called so TooltipDrawable can calculate where it is being drawn within the visible display.

Summary

XML attributes

Tooltip_android_layout_margin  
Tooltip_android_minHeight  
Tooltip_android_minWidth  
Tooltip_android_padding  
Tooltip_android_text  
Tooltip_android_textAppearance  

Inherited constants

From class com.google.android.material.shape.MaterialShapeDrawable

Public methods

static TooltipDrawable create(Context context)
static TooltipDrawable createFromAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Returns a TooltipDrawable from the given attributes.

static TooltipDrawable createFromAttributes(Context context, AttributeSet attrs)

Returns a TooltipDrawable from the given attributes.

void detachView(View view)

Should be called when the view is detached from the screen.

void draw(Canvas canvas)
int getIntrinsicHeight()
int getIntrinsicWidth()
int getLayoutMargin()

Returns the margin around the TooltipDrawable.

int getMinHeight()

Returns the minimum height of TooltipDrawable in terms of pixels.

int getMinWidth()

Returns the minimum width of TooltipDrawable in terms of pixels.

CharSequence getText()

Return the text that TooltipDrawable is displaying.

TextAppearance getTextAppearance()

Returns the TextAppearance used by this tooltip.

int getTextPadding()

Returns the padding between the text of TooltipDrawable and the sides in terms of pixels.

boolean onStateChange(int[] state)
void onTextSizeChange()
void setLayoutMargin(int layoutMargin)

Sets the margin around the TooltipDrawable to be margin.

void setMinHeight(int minHeight)

Sets the height of the TooltipDrawable to be at least minHeight wide.

void setMinWidth(int minWidth)

Sets the width of the TooltipDrawable to be at least minWidth wide.

void setRelativeToView(View view)

Should be called to allow this drawable to calculate its position within the current display frame.

void setText(CharSequence text)

Sets the text to be displayed.

void setTextAppearance(TextAppearance textAppearance)

Sets this tooltip's text appearance.

void setTextAppearanceResource(int id)

Sets this tooltip's text appearance using a resource id.

void setTextPadding(int padding)

Sets the padding between the text of the TooltipDrawable and the sides to be padding.

void setTextResource(int id)

Sets the text to be displayed using a string resource identifier.

Protected methods

void onBoundsChange(Rect bounds)

Inherited methods

From class com.google.android.material.shape.MaterialShapeDrawable
From class android.graphics.drawable.Drawable
From class java.lang.Object
From interface androidx.core.graphics.drawable.TintAwareDrawable
From interface com.google.android.material.shape.Shapeable

XML attributes

Tooltip_android_layout_margin

Related methods:

Tooltip_android_minHeight

Related methods:

Tooltip_android_minWidth

Related methods:

Tooltip_android_padding

Related methods:

Tooltip_android_text

Related methods:

Tooltip_android_textAppearance

Related methods:

Public methods

create

TooltipDrawable create (Context context)

Parameters
context Context

Returns
TooltipDrawable

createFromAttributes

TooltipDrawable createFromAttributes (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Returns a TooltipDrawable from the given attributes.

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Returns
TooltipDrawable

createFromAttributes

TooltipDrawable createFromAttributes (Context context, 
                AttributeSet attrs)

Returns a TooltipDrawable from the given attributes.

Parameters
context Context

attrs AttributeSet

Returns
TooltipDrawable

detachView

void detachView (View view)

Should be called when the view is detached from the screen.

Parameters
view View

draw

void draw (Canvas canvas)

Parameters
canvas Canvas

getIntrinsicHeight

int getIntrinsicHeight ()

Returns
int

getIntrinsicWidth

int getIntrinsicWidth ()

Returns
int

getLayoutMargin

int getLayoutMargin ()

Returns the margin around the TooltipDrawable.

Related XML Attributes:

Returns
int

getMinHeight

int getMinHeight ()

Returns the minimum height of TooltipDrawable in terms of pixels.

Related XML Attributes:

Returns
int

See also:

getMinWidth

int getMinWidth ()

Returns the minimum width of TooltipDrawable in terms of pixels.

Related XML Attributes:

Returns
int

See also:

getText

CharSequence getText ()

Return the text that TooltipDrawable is displaying.

Related XML Attributes:

Returns
CharSequence

getTextAppearance

TextAppearance getTextAppearance ()

Returns the TextAppearance used by this tooltip.

Related XML Attributes:

Returns
TextAppearance

getTextPadding

int getTextPadding ()

Returns the padding between the text of TooltipDrawable and the sides in terms of pixels.

Related XML Attributes:

Returns
int

onStateChange

boolean onStateChange (int[] state)

Parameters
state int

Returns
boolean

onTextSizeChange

void onTextSizeChange ()

setLayoutMargin

void setLayoutMargin (int layoutMargin)

Sets the margin around the TooltipDrawable to be margin.

Related XML Attributes:

Parameters
layoutMargin int: the margin to use around the TooltipDrawable

See also:

setMinHeight

void setMinHeight (int minHeight)

Sets the height of the TooltipDrawable to be at least minHeight wide.

Related XML Attributes:

Parameters
minHeight int: the minimum height of TooltipDrawable in terms of pixels

See also:

setMinWidth

void setMinWidth (int minWidth)

Sets the width of the TooltipDrawable to be at least minWidth wide.

Related XML Attributes:

Parameters
minWidth int: the minimum width of TooltipDrawable in terms of pixels

See also:

setRelativeToView

void setRelativeToView (View view)

Should be called to allow this drawable to calculate its position within the current display frame. This allows it to apply to specified window padding.

Parameters
view View

See also:

setText

void setText (CharSequence text)

Sets the text to be displayed.

Related XML Attributes:

Parameters
text CharSequence: text to be displayed

setTextAppearance

void setTextAppearance (TextAppearance textAppearance)

Sets this tooltip's text appearance.

Related XML Attributes:

Parameters
textAppearance TextAppearance: This tooltip's text appearance.

setTextAppearanceResource

void setTextAppearanceResource (int id)

Sets this tooltip's text appearance using a resource id.

Related XML Attributes:

Parameters
id int: The resource id of this tooltip's text appearance.

setTextPadding

void setTextPadding (int padding)

Sets the padding between the text of the TooltipDrawable and the sides to be padding.

Related XML Attributes:

Parameters
padding int: the padding to use around the text

See also:

setTextResource

void setTextResource (int id)

Sets the text to be displayed using a string resource identifier.

Related XML Attributes:

Parameters
id int: the resource identifier of the string resource to be displayed

Protected methods

onBoundsChange

void onBoundsChange (Rect bounds)

Parameters
bounds Rect