[MaterialToolbar] Add null check for logo ConstantState check

Resolves https://github.com/material-components/material-components-android/issues/2708

PiperOrigin-RevId: 449305810
This commit is contained in:
dsn5ft 2022-05-17 16:46:03 -04:00 committed by Avigail F
parent 722756e389
commit 2ac796fdf4

View File

@ -90,12 +90,17 @@ public class ToolbarUtils {
@Nullable
private static ImageView getImageView(@NonNull Toolbar toolbar, @Nullable Drawable content) {
if (content == null) {
return null;
}
for (int i = 0; i < toolbar.getChildCount(); i++) {
View child = toolbar.getChildAt(i);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
if (content != null
&& imageView.getDrawable().getConstantState().equals(content.getConstantState())) {
Drawable drawable = imageView.getDrawable();
if (drawable != null
&& drawable.getConstantState() != null
&& drawable.getConstantState().equals(content.getConstantState())) {
return imageView;
}
}