当我在API 19设备上运行我的应用程序时收到此错误。在API 24上运行它可以正常工作。

这是我的代码:

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "com.example.johng.assosfood"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:28.0.0-alpha1'
    implementation 'com.android.support:support-vector-drawable:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
    implementation 'com.google.android.gms:play-services-location:15.0.1'

}
apply plugin: 'com.google.gms.google-services'


fragment_login.xml

<?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" />




colors.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>


Styles.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>




错误日志

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


LoginFragment.java

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;
    }
}


令人讨厌的部分是它昨天工作了。我唯一更改的是TextInputEditTextTextInputLayout的一些颜色属性。我从textColorHint删除了TextInputLayout属性,并将我想要的textColor更新为TextInputEditText。除此之外,我只是更改了父活动的背景图像和片段上的imageView

编辑

好像我删除drawableRightdrawableEnd一样,问题就解决了。

最佳答案

Redundantia


  冗余属性drawableRight;已经用targetSdkVersion定义了drawableEnd少了27个


删除您的drawableRight

弃用


  对于paddingLeft和layout_marginLeft等XML属性,请使用paddingStart和layout_marginStart。注意:如果您的minSdkVersion小于17,则应同时添加较旧的left / right属性和新的start / right属性。在较旧的平台上,其中不支持RTL并且start / right属性是未知的,因此被忽略,因此您需要较旧的left / right属性。有一个单独的lint检查可以捕获这种类型的错误。


同样适用于drawableRight,他不是必需的,而是使用drawableLeft

关于java - 在API 19设备上膨胀TextInputEditText时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50760104/

10-10 03:19