public class

ButtonColors

extends java.lang.Object

 java.lang.Object

↳androidx.wear.protolayout.material.ButtonColors

Gradle dependencies

compile group: 'androidx.wear.protolayout', name: 'protolayout-material', version: '1.2.0'

  • groupId: androidx.wear.protolayout
  • artifactId: protolayout-material
  • version: 1.2.0

Artifact androidx.wear.protolayout:protolayout-material:1.2.0 it located at Google repository (https://maven.google.com/)

Overview

Represents the background and content colors used in Button.

See ButtonDefaults.PRIMARY_COLORS for the default colors used in a primary styled Button. See ButtonDefaults.SECONDARY_COLORS for the default colors used in a secondary styled Button.

Summary

Constructors
publicButtonColors(ColorBuilders.ColorProp backgroundColor, ColorBuilders.ColorProp contentColor)

Constructor for ButtonColors object.

publicButtonColors(int backgroundColor, int contentColor)

Constructor for ButtonColors object.

Methods
public ColorBuilders.ColorPropgetBackgroundColor()

The background color to be used on Button.

public ColorBuilders.ColorPropgetContentColor()

The content or tint color to be used on Button.

public static ButtonColorsprimaryButtonColors(Colors colors)

Returns a ButtonColors object, using the current Primary colors from the given Colors.

public static ButtonColorssecondaryButtonColors(Colors colors)

Returns a ButtonColors object, using the current Surface colors from the given Colors.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ButtonColors(int backgroundColor, int contentColor)

Constructor for ButtonColors object.

Parameters:

backgroundColor: The background color to be used for Button. Should be in ARGB format.
contentColor: The content color or tint color to be used for Button. Should be in ARGB format.

public ButtonColors(ColorBuilders.ColorProp backgroundColor, ColorBuilders.ColorProp contentColor)

Constructor for ButtonColors object.

Parameters:

backgroundColor: The background color to be used for a button.
contentColor: The content color or tint color to be used for a button.

Methods

public static ButtonColors primaryButtonColors(Colors colors)

Returns a ButtonColors object, using the current Primary colors from the given Colors.

public static ButtonColors secondaryButtonColors(Colors colors)

Returns a ButtonColors object, using the current Surface colors from the given Colors.

public ColorBuilders.ColorProp getBackgroundColor()

The background color to be used on Button.

public ColorBuilders.ColorProp getContentColor()

The content or tint color to be used on Button.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.wear.protolayout.material;

import static androidx.wear.protolayout.ColorBuilders.argb;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.wear.protolayout.ColorBuilders.ColorProp;

/**
 * Represents the background and content colors used in {@link Button}.
 *
 * <p>See {@link ButtonDefaults#PRIMARY_COLORS} for the default colors used in a primary styled
 * {@link Button}. See {@link ButtonDefaults#SECONDARY_COLORS} for the default colors used in a
 * secondary styled {@link Button}.
 */
public class ButtonColors {
    @NonNull private final ColorProp mBackgroundColor;
    @NonNull private final ColorProp mContentColor;

    /**
     * Constructor for {@link ButtonColors} object.
     *
     * @param backgroundColor The background color to be used for {@link Button}. Should be in ARGB
     *     format.
     * @param contentColor The content color or tint color to be used for {@link Button}. Should be
     *     in ARGB format.
     */
    public ButtonColors(@ColorInt int backgroundColor, @ColorInt int contentColor) {
        mBackgroundColor = argb(backgroundColor);
        mContentColor = argb(contentColor);
    }

    /**
     * Constructor for {@link ButtonColors} object.
     *
     * @param backgroundColor The background color to be used for a button.
     * @param contentColor The content color or tint color to be used for a button.
     */
    public ButtonColors(@NonNull ColorProp backgroundColor, @NonNull ColorProp contentColor) {
        mBackgroundColor = backgroundColor;
        mContentColor = contentColor;
    }

    /**
     * Returns a {@link ButtonColors} object, using the current Primary colors from the given {@link
     * Colors}.
     */
    @NonNull
    public static ButtonColors primaryButtonColors(@NonNull Colors colors) {
        return new ButtonColors(colors.getPrimary(), colors.getOnPrimary());
    }

    /**
     * Returns a {@link ButtonColors} object, using the current Surface colors from the given {@link
     * Colors}.
     */
    @NonNull
    public static ButtonColors secondaryButtonColors(@NonNull Colors colors) {
        return new ButtonColors(colors.getSurface(), colors.getOnSurface());
    }

    /** The background color to be used on {@link Button}. */
    @NonNull
    public ColorProp getBackgroundColor() {
        return mBackgroundColor;
    }

    /** The content or tint color to be used on {@link Button}. */
    @NonNull
    public ColorProp getContentColor() {
        return mContentColor;
    }
}