mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
am 2dd67ac0: am 8c6f2081: Merge "Add more helpful exception to design components" into mnc-ub-dev
* commit '2dd67ac062eb7f7a9a83e4f864eb27b15f416f48': Add more helpful exception to design components GitOrigin-RevId=65fb4571ce472e3ea5d654f51025bb84925f5b22 PiperOrigin-RevId: 140549518
This commit is contained in:
parent
6a31677d90
commit
d907dd4deb
@ -142,6 +142,8 @@ public class AppBarLayout extends LinearLayout {
|
||||
super(context, attrs);
|
||||
setOrientation(VERTICAL);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppBarLayout,
|
||||
0, R.style.Widget_Design_AppBarLayout);
|
||||
mTargetElevation = a.getDimensionPixelSize(R.styleable.AppBarLayout_elevation, 0);
|
||||
|
||||
@ -126,6 +126,8 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
public CollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
mCollapsingTextHelper = new CollapsingTextHelper(this);
|
||||
mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);
|
||||
|
||||
|
||||
@ -168,6 +168,8 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen
|
||||
public CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout,
|
||||
defStyleAttr, R.style.Widget_Design_CoordinatorLayout);
|
||||
final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0);
|
||||
|
||||
@ -82,6 +82,8 @@ public class FloatingActionButton extends ImageView {
|
||||
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
mShadowPadding = new Rect();
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
|
||||
@ -95,6 +95,8 @@ public class NavigationView extends ScrimInsetsFrameLayout {
|
||||
public NavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
// Create the menu
|
||||
mMenu = new NavigationMenu(context);
|
||||
|
||||
|
||||
@ -181,6 +181,8 @@ public final class Snackbar {
|
||||
mParent = parent;
|
||||
mContext = parent.getContext();
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(mContext);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mView = (SnackbarLayout) inflater.inflate(R.layout.design_layout_snackbar, mParent, false);
|
||||
}
|
||||
|
||||
@ -222,6 +222,8 @@ public class TabLayout extends HorizontalScrollView {
|
||||
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
// Disable the Scroll Bar
|
||||
setHorizontalScrollBarEnabled(false);
|
||||
// Set us to fill the View port
|
||||
|
||||
@ -85,6 +85,8 @@ public class TextInputLayout extends LinearLayout {
|
||||
// Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
|
||||
super(context, attrs);
|
||||
|
||||
ThemeUtils.checkAppCompatTheme(context);
|
||||
|
||||
setOrientation(VERTICAL);
|
||||
setWillNotDraw(false);
|
||||
setAddStatesFromChildren(true);
|
||||
|
||||
38
src/android/support/design/widget/ThemeUtils.java
Normal file
38
src/android/support/design/widget/ThemeUtils.java
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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 android.support.design.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.design.R;
|
||||
|
||||
class ThemeUtils {
|
||||
|
||||
private static final int[] APPCOMPAT_CHECK_ATTRS = { R.attr.colorPrimary };
|
||||
|
||||
static void checkAppCompatTheme(Context context) {
|
||||
TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS);
|
||||
final boolean failed = !a.hasValue(0);
|
||||
if (a != null) {
|
||||
a.recycle();
|
||||
}
|
||||
if (failed) {
|
||||
throw new IllegalArgumentException("You need to use a Theme.AppCompat theme "
|
||||
+ "(or descendant) with the design library.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user