为什么“找不到android.support.design.widget.TextInputLayout”?

时间:2019-07-16 08:51:48

标签: java android xml android-studio gradle

我的Android Studio版本为3.4,compileSdkVersion 29和buildToolsVersion“ 29.0.1”。我想使用TextInputLayout,但出现此错误: 缺少课程: 找不到以下类别: -android.support.design.widget.TextInputLayout(修复构建路径,编辑XML,创建类)  提示:尝试构建项目。

我搜索了几天。我添加了

implementation 'com.android.support:appcompat-v7:29.0.1'
implementation 'com.android.support:design:29.0.1'

到我的gradle文件。但是此错误仍然存​​在。

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.example.studentv3.tools.RoundImageView
        android:id="@+id/admin_layout_pic"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:src="@drawable/admin_photo" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/tt2"
        android:layout_below="@+id/admin_layout_pic"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/admin_login_activity_name_input"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_below="@+id/admin_layout_pic"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/input_box"
            android:gravity="center"
            android:hint="请输入账户"
            android:maxLines="1"
            android:paddingLeft="@dimen/input_box_left_padding"
            android:textColor="@color/grey_text" />

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



    <android.support.design.widget.TextInputLayout
        android:id="@+id/tt3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tt2">
        <EditText
            android:id="@+id/admin_login_activity_password_input"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_below="@+id/tt2"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/input_box"
            android:gravity="center"
            android:hint="请输入密码"
            android:inputType="numberPassword"
            android:maxLines="1"
            android:paddingLeft="@dimen/input_box_left_padding"
            android:textColor="@color/grey_text" />

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

这是我的礼物:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.studentv3"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
    testImplementation 'junit:junit:4.13-beta-3'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
    implementation 'com.android.support:appcompat-v7:29.0.1'
    implementation 'com.android.support:design:29.0.1'
    //api 'com.android.support:design:29.0.0'
    implementation 'com.google.android.material:material:1.0.0'
}

该xml的java类中没有错误,但我将其放在此处:

package com.example.studentv3.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.studentv3.tools.myDatabaseHelper;
import com.example.studentv3.R;



public class admin_login_activity extends Activity {
    private EditText name;
    private EditText password;
    private Button login;
    private TextView register;
    private TextView forgetNum;
    private myDatabaseHelper dbHelper;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.admin_login_layout);

        dbHelper = myDatabaseHelper.getInstance(this);


        name = (EditText) findViewById(R.id.admin_login_activity_name_input);
        password = (EditText) findViewById(R.id.admin_login_activity_password_input);
        login = (Button) findViewById(R.id.admin_login_activity_login);
        register = (TextView) findViewById(R.id.admin_login_activity_register);
        forgetNum = (TextView) findViewById(R.id.admin_login_activity_forgetNum);


        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String nameInfo = name.getText().toString();
                String passwordInfo = password.getText().toString();

                SQLiteDatabase db = dbHelper.getWritableDatabase();
                Cursor cursor = db.rawQuery("select password from admin where name=?", new String[]{nameInfo});
                String pi = null;
                if (cursor.moveToNext()) {
                    pi = cursor.getString(cursor.getColumnIndex("password"));
                }

                if (passwordInfo.equals(pi)) {
                    Intent intent = new Intent(admin_login_activity.this, admin_activity.class);
                    startActivity(intent);
                    cursor.close();
                } else {
                    Toast.makeText(admin_login_activity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
                }


            }
        });


        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(admin_login_activity.this);
                LayoutInflater factory = LayoutInflater.from(admin_login_activity.this);
                final View textEntryView = factory.inflate(R.layout.register, null);
                builder.setTitle("用户注册");
                builder.setView(textEntryView);

                final EditText code = (EditText) textEntryView.findViewById(R.id.admin_register_info);
                final EditText name = (EditText) textEntryView.findViewById(R.id.admin_register_name);
                final EditText firstPassword = (EditText) textEntryView.findViewById(R.id.admin_register_first_password);
                final EditText secondPassword = (EditText) textEntryView.findViewById(R.id.admin_register_second_password);


                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });

                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String codeInfo = code.getText().toString();

                        if (codeInfo.equals("10086")) {
                            String nameInfo = name.getText().toString();
                            String firstPasswordInfo = firstPassword.getText().toString();
                            String secondPasswordInfo = secondPassword.getText().toString();
                            SQLiteDatabase db = dbHelper.getWritableDatabase();

                            if (firstPasswordInfo.matches("[0-9]{6}")) {

                                if (firstPasswordInfo.equals(secondPasswordInfo)) {
                                    Cursor cursor = db.rawQuery("select name from admin where name=? ", new String[]{nameInfo});

                                    if (cursor.moveToNext()) {
                                        Toast.makeText(admin_login_activity.this, "该用户已存在", Toast.LENGTH_SHORT).show();
                                    } else {
                                        db.execSQL("insert into admin(name,password)values(?,?)", new String[]{nameInfo, firstPasswordInfo});
                                    }
                                } else {
                                    Toast.makeText(admin_login_activity.this, "两次密码不相同", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(admin_login_activity.this, "密码为6位纯数字", Toast.LENGTH_SHORT).show();
                            }


                        } else {
                            Toast.makeText(admin_login_activity.this, "注册码错误", Toast.LENGTH_SHORT).show();
                        }
                    }
                });


                builder.create().show();

            }
        });

        forgetNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(admin_login_activity.this, "此功能暂不支持", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

该项目可以运行并且可以在我的手机(android 9)上使用,但是当我进入xml上面控制的页面时,该应用突然关闭。我认为原因是xml出现此错误:找不到android .support.design.widget.TextInputLayout。因为我尝试删除提及TextInputLayout的所有代码,所以该代码不会关闭,但这不是我的预期结果。

2 个答案:

答案 0 :(得分:0)

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/in1"
            android:layout_width="match_parent"
            android:layout_marginTop="20dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:textColorHint="#353536"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_height="wrap_content"
            app:passwordToggleEnabled="true">

            <EditText
                android:id="@+id/loginPass"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:ems="10"
                android:inputType="textPassword"
                android:hint="@string/loginPassword"
                android:paddingLeft="10dp" />
        </com.google.android.material.textfield.TextInputLayout
  

Blockquote

答案 1 :(得分:-1)

您可以使用材质设计来实现TextInputEditText和TextInputLayout。

使用材料设计的最新版本:

SELECT equipment.ID AS EquipmentID,
       MAX(CONDITION_DATE), 
FROM CONDITION
  LEFT JOIN EQUIPMENT 
         ON condition.GUID_EQUIPMENT = EQUIPMENT.GUID
  LEFT JOIN Condition_type 
         ON Condition.GUID_CONDITION_TYPE = condition_type.guid
WHERE IS_DEACTIVATED = '0' 
  AND equipment.HAS_CONDITION_CONTROL = '1' 
  AND Condition_type.DESCRIPTION IS NOT NULL
GROUP BY equipment.ID

然后实施如下。

api 'com.google.android.material:material:1.1.0-alpha06'