繁体   English   中英

android.view.InflateException:二进制 XML 文件第 27 行:android.support.design.widget.TextInputEditText 不能转换为 android.view.ViewGroup

[英]android.view.InflateException: Binary XML file line #27: android.support.design.widget.TextInputEditText cannot be cast to android.view.ViewGroup

我创建了一个登录布局,但是当我尝试编写这一行时

setContentView(R.layout.activity_login);

它显示了一个错误

ERROR: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.look.instragramclone/com.example.look.instragramclone.Likes.LikesActivity}: android.view.InflateException: Binary XML file line #27: android.support.design.widget.TextInputEditText cannot be cast to android.view.ViewGroup

我找不到问题。 我正在添加相关代码

我尝试添加这些库:

实现 fileTree(dir: 'libs', include: ['*.jar']) 实现 'com.android.support:appcompat-v7:28.0.0'

//协调器布局实现的设计支持库'com.android.support:design:28.0.0'

实现 'com.github.ittianyu:BottomNavigationViewEx:2.0.2'

//圆形图片实现 'de.hdodenhof:circleimageview:3.0.0'

//通用图像加载器实现 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

登录布局:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="55dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="70dp"
            android:src="@drawable/instagram_logo"
            android:layout_gravity="center"
            android:layout_marginBottom="25dp"/>

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email"
                android:id="@+id/input_email"/>

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

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password"
                android:id="@+id/input_password"/>

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

        <android.support.v7.widget.AppCompatButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="25dp"
            android:text="Login"
            android:id="@+id/btn_Login"
            android:padding="12dp"
            android:background="@drawable/white_rounded_btn"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="25dp"
            android:text="No account yet? Create one"
            android:gravity="center"
            android:textSize="16dp"
            android:id="@+id/link_singup"
            android:textColor="@color/blue"/>

    </LinearLayout>

    <ProgressBar
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/loginRequestLoadingProgressBar"
        android:layout_centerInParent="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pleasr wait..."
        android:textColor="@color/black"
        android:textSize="20sp"
        android:layout_alignBottom="@+id/loginRequestLoadingProgressBar"
        android:layout_alignStart="@id/loginRequestLoadingProgressBar"
        android:layout_alignEnd="@id/loginRequestLoadingProgressBar"/>


</RelativeLayout>

爪哇:

private static final String TAG = "LikesActivity";

private Context mContext = LikesActivity.this;

private static final int ACTIVITY_NO = 3;


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_login);
    -->Note: this line shows the error

    //setupNavigationView();
}
/***BottomNavigationView setup***/

private void setupNavigationView(){

    BottomNavigationViewEx bottomNavigationViewEx = findViewById(R.id.bottomNavViewBar);
    BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationViewEx);
    BottomNavigationViewHelper.enableNavigation(mContext,bottomNavigationViewEx);
    Menu menu = bottomNavigationViewEx.getMenu();
    MenuItem menuItem = menu.getItem(ACTIVITY_NO);
    menuItem.setChecked(true);
}

使用 TextInputEdittext 的 TextInputLayout 插入。

以下代码用于 textinputlayout 使用:

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

<EditText
    android:id="@+id/username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:hint="Email"/> 

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

您不能通过在以下 xml 中放置子项来将 TextInputEditText 视为 ViewGroup -

<android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"
            android:hint="Email"
            android:id="@+id/input_email"/>

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

您需要使用它作为视图使用 -

        <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"/> // close this tag here

我遇到了同样的问题,显然我的InputLayout的样式没有正确配置我尝试更改它并且错误得到了解决,我们还可以在InputTextLayout使用EditText而不是InputEditText

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM