无法实例化android.support.design.widget.TextInputLayout

时间:2018-03-22 05:04:32

标签: android android-studio android-appcompat android-theme android-textinputlayout

我正在尝试使用android.support.design.widget.TextInputLayout,但我得到了这个异常

  

java.lang.IllegalArgumentException:您需要将Theme.AppCompat主题(或后代)与设计库一起使用。       在android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33)       在android.support.design.widget.TextInputLayout。(TextInputLayout.java:193)       在android.support.design.widget.TextInputLayout。(TextInputLayout.java:186)       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)       在org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)       在org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)       在org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)       在com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)       在android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)       在android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)       在android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)       在android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)       在android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)       在android.view.LayoutInflater.rInflate(LayoutInflater.java:834)       在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)       在android.view.LayoutInflater.inflate(LayoutInflater.java:518)       在android.view.LayoutInflater.inflate(LayoutInflater.java:397)       在com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)       在com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)       在com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)       在com.android.tools.idea.rendering.RenderTask $ 2.compute(RenderTask.java:548)       在com.android.tools.idea.rendering.RenderTask $ 2.compute(RenderTask.java:533)       在com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)       在com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)       在com.android.tools.idea.rendering.RenderTask.lambda $ inflate $ 70(RenderTask.java:659)       at java.util.concurrent.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)       在java.lang.Thread.run(Thread.java:745)

我的gradle模块文件包含:

compile 'com.android.support:design:26.0.1'
compile 'com.android.support:appcompat-v7:26.0.1'

活性-main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.eltobgy.yala.MainActivity">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <AutoCompleteTextView
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true" />

    </android.support.design.widget.TextInputLayout>

</LinearLayout>

styles.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    </style>

    <style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/colorAccent</item>
    </style>

    <style name="label_text">
        <item name="android:textSize">19sp</item>
        <item name="android:textColor">@android:color/black</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="text">
        <item name="android:textSize">14sp</item>
        <item name="android:textColor">@color/gray</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>

    </style>

    <style name="line">
        <item name="android:layout_marginBottom">8dp</item>
        <item name="android:layout_marginTop">8dp</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/colorAccent</item>
        <item name="android:shadowColor">@color/colorAccent</item>
        <item name="android:shadowDx">0</item>
        <item name="android:shadowDy">0</item>
        <item name="android:shadowRadius">8</item>
    </style>

    <!--FIREBASE UI-->
    <style name="LoginTheme" parent="FirebaseUI">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorButtonNormal">@color/colorAccent</item>
        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorControlActivated">@android:color/white</item>
        <item name="colorControlHighlight">@android:color/white</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:colorBackground">@color/colorPrimary</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:textColorHint">@android:color/white</item>
    </style>

    <style name="FirebaseUI.Text">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:fontFamily">sans-serif</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

    <style name="FirebaseUI.Text.Link">
        <item name="android:textColor">@color/colorSecondary</item>
    </style>


    <color name="colorSecondary">#FFC300</color>
    <color name="gray">#FFF0</color>


</resources>

MainActivity.java

package com.example.eltobgy.yala;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.ui.auth.AuthUI;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.FirebaseUserMetadata;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String ANONYMOUS = "Anonymous";
    // Choose an arbitrary request code value
    private static final int RC_SIGN_IN = 1;
    Boolean flag_registered = false;
    // Firebase
    private FirebaseAuth mFirebaseAuth;
    private FirebaseAuth.AuthStateListener mAuthStateListener;
    private ChildEventListener mChildEventListener;
    private String mUsername;
    private DatabaseReference mDatabaseReference;
    private FirebaseDatabase mDatabase;

    private User currentUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mUsername = ANONYMOUS;
        mFirebaseAuth = FirebaseAuth.getInstance();
        mDatabase = FirebaseDatabase.getInstance();
        currentUser = null;
        mDatabaseReference = mDatabase.getReference().child("users");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAuthStateListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();

                if (firebaseUser != null) {
                    // User is signed in
                    FirebaseUserMetadata metadata = firebaseAuth.getCurrentUser().getMetadata();

                    onSignedInInitialize(firebaseUser.getDisplayName());
                    Toast.makeText(MainActivity.this, "You're now signed in. Welcome " + firebaseUser.getDisplayName() + "!", Toast.LENGTH_SHORT).show();
                    DatabaseReference userDatabaseRefrence = mDatabaseReference.child(firebaseUser.getUid());
                    ValueEventListener valueEventListener = new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            currentUser = dataSnapshot.getValue(User.class);
                            if(currentUser.getCurrentType().equals("c")){
                                //customer
                                if(currentUser.isCustomerModeActivation()){
                                    //already filled details
                                    //TODO go to next activity
                                }else{
                                    //didn't fill details

                                }
                            }
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                            Toast.makeText(MainActivity.this, "cancelled", Toast.LENGTH_SHORT).show();
                        }
                    };
                    userDatabaseRefrence.addValueEventListener(valueEventListener);
                } else {
                    // User is signed out
                    onSignedOutCleanup();

                    List<AuthUI.IdpConfig> providers = Arrays.asList(
                            new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
                            new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build());

                    startActivityForResult(
                            AuthUI.getInstance()
                                    .createSignInIntentBuilder()
                                    .setIsSmartLockEnabled(false)
                                    .setAvailableProviders(providers)
                                    .setTheme(R.style.LoginTheme)
                                    //.setLogo(R.drawable.ic_melomania_blue_light)
                                    .build(),
                            RC_SIGN_IN);
//RC request code, it's a flag for when we return rom starting the activity for the results.
                }
            }
        };

    }

无效缓存/重启&amp;重建项目不起作用。

1 个答案:

答案 0 :(得分:0)

尝试将app gradle更改为

compileSdkVersion 27 targetSdkVersion 27

编译'com.android.support:design:27.1.0' 实现'com.android.support:appcompat-v7:27.1.0'