Skip to content

Button Preference

Screenshot

This shows a simple button preference. It allows you to handle a click action.

Check out the composable and it's documentation in the code snipplet below.

Example#

PreferenceButton(
    title = "Button 1",
    subtitle = "Clicking this button will increase counter 1",
    icon = { Icon(Icons.Default.AdsClick, null) },
    onClick = {
        ToastHelper.show(context, "Button 1 clicked!")
        counter1++
    }
)

Composable#

/**
 * A button preference item - this item simply executes an action on click
 *
 *  
 *
 * **Basic Parameters:** all params not described here are derived from [com.michaelflisar.composepreferences.core.composables.BasePreference], check it out for more details
 *
 * @param onClick the click callback of this item
 */
@Composable
fun PreferenceScope.PreferenceButton(
    // Special
    onClick: (() -> Unit),
    // Base Preference
    title: String,
    enabled: Dependency = Dependency.Enabled,
    visible: Dependency = Dependency.Enabled,
    subtitle: String? = null,
    icon: (@Composable () -> Unit)? = null,
    itemStyle: PreferenceItemStyle = LocalPreferenceSettings.current.style.defaultItemStyle,
    titleRenderer: @Composable (text: AnnotatedString) -> Unit = { Text(it) },
    subtitleRenderer: @Composable (text: AnnotatedString) -> Unit = { Text(it) },
    filterTags: List<String> = emptyList()
)
{
    BasePreference(
        enabled = enabled,
        visible = visible,
        title = title,
        subtitle = subtitle,
        icon = icon,
        onClick = onClick,
        itemStyle = itemStyle,
        titleRenderer = titleRenderer,
        subtitleRenderer = subtitleRenderer,
        filterTags = filterTags,
        content = null
    )
}

Screenshots#

Screenshot Screenshot