SliceView
@RequiresApi(19) open class SliceView : ViewGroup, Observer<Slice!>, OnClickListener
kotlin.Any | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | androidx.slice.widget.SliceView |
A view for displaying Slice
s.
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 androidx.slice.builders.TemplateSliceBuilder
.
SliceView is able to display slices in a couple of different modes via {@see #setMode}.
- 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, {@see #setScrollable}.
- 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()); v.setMode(desiredMode); LiveData<slice> liveData = SliceLiveData.fromUri(sliceUri); liveData.observe(lifecycleOwner, v); </slice>
SliceView supports various style options, see SliceView Attributes
.
Summary
Nested classes | |
---|---|
abstract |
Implement this interface to be notified of interactions with the slice displayed in this view. |
Constants | |
---|---|
static Int |
Mode indicating this slice should be presented in large format, as much or all of the slice contents are shown. |
static Int |
Mode indicating this slice should be presented as a tappable icon. |
static Int |
Mode indicating this slice should be presented in small format, only top-level information and actions from the slice are shown. |
Public constructors | |
---|---|
<init>(context: Context!, @Nullable attrs: AttributeSet?) |
|
<init>(context: Context!, @Nullable attrs: AttributeSet?, defStyleAttr: Int) |
|
<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int) |
Public methods | |
---|---|
open Int |
Returns the number of slice items not displayed in this view. |
open Int |
getMode() |
open Slice? |
getSlice() |
open MutableList<SliceAction!>? |
Returns the slice actions presented in this view. |
open Boolean |
Whether this view allow scrollable content when presenting in |
open Unit | |
open Unit | |
open Boolean | |
open Boolean |
onTouchEvent(ev: MotionEvent!) |
open Unit |
setAccentColor(@ColorInt accentColor: Int) Contents of a slice such as icons, text, and controls (e.g. toggle) can be tinted. |
open Unit |
Set the mode this view should present in. |
open Unit |
setOnClickListener(listener: OnClickListener?) |
open Unit |
setOnLongClickListener(listener: OnLongClickListener?) |
open Unit |
setOnSliceActionListener(@Nullable observer: SliceView.OnSliceActionListener?) Sets the listener to notify when an interaction event occurs on the view. |
open Unit |
setRowStyleFactory(@Nullable rowStyleFactory: RowStyleFactory?) Sets the |
open Unit |
setScrollable(isScrollable: Boolean) Set whether this view should allow scrollable content when presenting in |
open Unit |
setShowActionDividers(enabled: Boolean) Whether this view should show action dividers for rows. |