我在API 19设备上运行我的应用时遇到此错误。在API 24上运行它可以正常工作。
这是我的代码:
的build.gradle
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="142dp"
android:src="@drawable/logo_black" />
<android.support.design.widget.TextInputLayout
android:id="@+id/emailLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/email"
android:drawableRight="@drawable/email"
android:textColor="@color/colorAccent"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/passwordLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/pass"
android:drawableRight="@drawable/pass"
android:textColor="@color/colorAccent"
android:hint="@string/prompt_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/colorAccent"
android:ellipsize="none"
android:onClick="validateLogin"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:text="@string/emailLoginButton"
android:textColor="@color/colorWhite" />
<TextView
android:textAlignment="center"
android:layout_width="match_parent"
android:onClick="swipeToRegister"
android:clickable="true"
android:focusable="true"
android:layout_height="wrap_content"
android:text="@string/prompt_notAUser" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clickable="true"
android:focusable="true"
android:onClick="resetPassword"
android:text="@string/prompt_forgotPassword"
android:textAlignment="center" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="@string/credits"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
fragment_login.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimaryLighter">#444444</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#FF0C2A</color>
<color name="colorWhite">#FFFFFF</color>
<color name="colorGray">#EEEEEE</color>
</resources>
colors.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
<style name="AppTheme.ActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
</style>
Styles.xml
FATAL EXCEPTION: main
Process: com.example.johng.assosfood, PID: 10900
android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.TextInputEditText
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.johng.assosfood.LoginFragment.onCreateView(LoginFragment.java:14)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2335)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1423)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1754)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1822)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2591)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2378)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2333)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2210)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1239)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1087)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1617)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:734)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:806)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
at android.view.View.measure(View.java:16834)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2368)
at android.view.View.measure(View.java:16834)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2246)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1312)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
at a E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
错误日志
public class LoginFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_login, container, false);
return rootView;
}
public String validation(String email, String password) {
String msg = "";
if(email.trim().isEmpty()) {
msg = "...";
} else if(password.trim().isEmpty()) {
msg = "...";
}
return msg;
}
}
LoginFragment.java
TextInputEditText
令人讨厌的部分是它昨天正在运作。我唯一改变的是TextInputLayout
和textColorHint
的一些颜色属性。我从TextInputLayout
删除了textColor
属性,并更新了我想要的TextInputEditText
imageView
。除了这些之外,我刚刚从父活动和片段上的drawableRight
更改了背景图像。
修改
似乎我删除了drawableEnd
和{{1}}问题已解决。
答案 0 :(得分:0)
<强> Reduntantia 强>
冗余属性drawableRight;已经使用targetSdkVersion减少了laableEnd 27
删除drawableRight
<强>弃用强>
对于诸如paddingLeft和layout_marginLeft的XML属性,请使用paddingStart和layout_marginStart。注意:如果您的minSdkVersion小于17,则应添加较旧的左/右属性以及新的开始/右侧属性。在较旧的平台上,不支持RTL并且启动/右侧属性未知且因此被忽略,您需要较旧的左/右属性。有一个单独的lint检查可以捕获这种类型的错误。
同样适用于drawableRight
,他不是必须的,请改用drawableLeft
答案 1 :(得分:0)
棒棒糖崩溃前的Android Vector Drawables-解决方案
做了很多研发工作,我得到了答案,我们需要以编程方式在textView,imageView,imageButton和EditText上设置drawable。
https://android.jlelse.eu/android-vector-drawables-on-pre-lollipop-crash-solution-45c0c34f0160
//region Helper method for PreLollipop TextView & Buttons Vector Images
public static Drawable setVectorForPreLollipop(int resourceId, Context activity) {
Drawable icon;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
icon = VectorDrawableCompat.create(activity.getResources(), resourceId, activity.getTheme());
} else {
icon = activity.getResources().getDrawable(resourceId, activity.getTheme());
}
return icon;
}