connieshi 5e35d14c18 [Badge] Update badge to support being anchored to any view in pre 18.
In <API18, BadgeDrawable will dynamically 1) wrap the anchor in a FrameLayout and 2) replace the anchor with the FrameLayout in the anchor' view hierarchy. BadgeDrawable will set itself as foreground on the FrameLayout.

If the user does not want BadgeDrawable to manipulate its view hierarchy, the user can pass in an instance of FrameLayout `customBadgeParent` in #attachBadgeDrawable instead.

Labeled BadgeUtils as experimental and removed the RestrictedTo(Scope.Library) annotation.

Updated TopAppBar main demo to show a badge on a toolbar menu item.

PiperOrigin-RevId: 336306885
2020-10-15 12:31:14 -07:00

38 lines
1.2 KiB
Java

/*
* Copyright 2020 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 com.google.android.material.badge;
import static androidx.annotation.experimental.Experimental.Level.ERROR;
import static java.lang.annotation.RetentionPolicy.CLASS;
import androidx.annotation.experimental.Experimental;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/** Annotation denoting this class is experimental */
@Retention(CLASS)
@Target({
ElementType.TYPE,
ElementType.METHOD,
ElementType.CONSTRUCTOR,
ElementType.FIELD,
ElementType.PACKAGE
})
@Experimental(level = ERROR)
public @interface ExperimentalBadgeUtils {}