public class SliceView
extends ViewGroup implements Observer<Slice>, View.OnClickListener

   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.slice.widget.SliceView

A view for displaying Slices.

A slice is a piece of app content and actions that can be surfaced outside of the app it originates from. SliceView is able to interpret the structure and contents of a slice and display it. This structure is defined by the app providing the slice when the slice is constructed with a TemplateSliceBuilder.

SliceView is able to display slices in a couple of different modes via .

  • Small: The small format has a restricted height and display top-level information and actions from the slice.
  • Large: The large format displays as much of the slice as it can based on the space provided for SliceView, if the slice overflows the space SliceView will scroll the content if scrolling has been enabled on SliceView, .
  • Shortcut: A shortcut shows minimal information and is presented as a tappable icon representing the main content or action associated with the slice.

Slices can contain dynamic content that may update due to user interaction or a change in the data being displayed in the slice. SliceView can be configured to listen for these updates easily using SliceLiveData. Example usage:

 SliceView v = new SliceView(getContext());
 LiveData liveData = SliceLiveData.fromUri(sliceUri);
 liveData.observe(lifecycleOwner, v);

SliceView supports various style options, see SliceView Attributes.


Nested classes

interface SliceView.OnSliceActionListener

Implement this interface to be notified of interactions with the slice displayed in this view. 



Mode indicating this slice should be presented in large format, as much or all of the slice contents are shown.


Mode indicating this slice should be presented as a tappable icon.


Mode indicating this slice should be presented in small format, only top-level information and actions from the slice are shown.

Inherited constants

Inherited fields

Public constructors

SliceView(Context context)
SliceView(Context context, AttributeSet attrs)
SliceView(Context context, AttributeSet attrs, int defStyleAttr)
SliceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

int getHiddenItemCount()

Returns the number of slice items not displayed in this view.

int getMode()
Slice getSlice()
List<SliceAction> getSliceActions()

Returns the slice actions presented in this view.

boolean isScrollable()

Whether this view allow scrollable content when presenting in MODE_LARGE.

void onChanged(Slice t)
void onClick(View v)
boolean onInterceptTouchEvent(MotionEvent ev)
boolean onTouchEvent(MotionEvent ev)
void setAccentColor(int accentColor)

Contents of a slice such as icons, text, and controls (e.g.

void setMode(int mode)

Set the mode this view should present in.

void setOnClickListener(View.OnClickListener listener)
void setOnLongClickListener(View.OnLongClickListener listener)
void setOnSliceActionListener(SliceView.OnSliceActionListener observer)

Sets the listener to notify when an interaction event occurs on the view.

void setRowStyleFactory(RowStyleFactory rowStyleFactory)

Sets the RowStyleFactory which allows multiple children to have different styles.

void setScrollable(boolean isScrollable)

Set whether this view should allow scrollable content when presenting in MODE_LARGE.

void setShowActionDividers(boolean enabled)

Whether this view should show action dividers for rows.

void setShowHeaderDivider(boolean enabled)

Whether this view should show the header divider.

void setShowTitleItems(boolean enabled)

Whether this view should show title items on the first row of the slice.

void setSlice(Slice slice)

Populates this view to the provided Slice.

void setSliceActions(List<SliceAction> newActions)

Sets the slice actions to display for the slice contained in this view.

Protected methods

void configureViewPolicy(int maxHeight)

Sets the maximum height for a slice through the view policy.

void onAttachedToWindow()
void onDetachedFromWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onVisibilityChanged(View changedView, int visibility)
void onWindowVisibilityChanged(int visibility)

Inherited methods