繁体   English   中英

为什么我的 xml 中的 textinputlayout 不显示?

[英]Why won't the textinputlayout in my xml show up?

我创建的 textinputlayout 用于登录屏幕,但是每当启动 Activity 时,除此之外的其他所有内容都会显示。 点击它应该在的空间也没有任何作用(键盘没有出现)所以它的可见性似乎已经被设置为“消失”,即使它没有。

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.thelatinschool.canvasgrades.SplashScreenActivity">

<ImageView
    android:id="@+id/logo"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:layout_centerInParent="true"
    android:contentDescription="@null"
    android:src="@mipmap/ic_launcher_round"
    android:visibility="visible" />

<ProgressBar
    android:id="@+id/loadingProgressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="12dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="-4dp"
    android:foregroundGravity="bottom"
    android:indeterminate="true"
    android:padding="0dp"
    android:theme="@style/ProgressBarStyle"
    android:visibility="visible" />

<RelativeLayout
    android:id="@+id/afterAnimationView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginStart="20dp"
    android:layout_marginTop="130dp"
    android:layout_marginEnd="20dp"
    android:orientation="vertical"
    android:visibility="visible">

    <TextView
        android:id="@+id/WelcomeTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Highlands Latin School"
        android:textColor="@color/colorPrimary"
        android:textSize="25sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/readItTogetherTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/WelcomeTextView"
        android:layout_marginTop="10dp"
        android:text="Canvas Grades"
        android:textColor="@color/colorAccent"
        android:textSize="15sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/loginButton"
        android:layout_below="@+id/readItTogetherTextView"
        android:gravity="center"
        android:orientation="vertical">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/emailEditText"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="Email"
            android:textColor="@color/colorPrimary"
            android:textColorHint="@color/colorAccent"
            android:textSize="15sp"
            app:boxBackgroundMode="outline" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/passwordEditText"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="25dp"
            android:hint="Password"
            android:textColor="@color/colorPrimary"
            android:textColorHint="@color/colorAccent"
            android:textSize="15sp"
            app:boxStrokeColor="#000000" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:padding="5dp">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end|center_vertical"
                android:background="#FFFFFF"
                android:text="Forgot Password?"
                android:textColor="@color/colorAccent"
                android:textSize="14sp"
                android:textStyle="bold" />
        </FrameLayout>
    </LinearLayout>

    <Button
        android:id="@+id/loginButton"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_above="@+id/skipTextView"
        android:layout_marginBottom="5dp"
        android:background="@drawable/button_drawable"
        android:text="Login"
        android:textAllCaps="false"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/skipTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:background="?android:attr/selectableItemBackground"
        android:clickable="true"
        android:focusable="true"
        android:gravity="center"
        android:padding="12dp"
        android:text="Incorrect username or password!"
        android:textColor="#B53737"
        android:textSize="15sp"
        android:visibility="invisible" />

</RelativeLayout>
</RelativeLayout>

和相应的java:

public class SplashScreenActivity extends AppCompatActivity {
public String theme1;
private ProgressDialog progressDialog;
private boolean animationStarted = false;
private ImageView bookIconImageView;
private TextView bookITextView;
private ProgressBar loadingProgressBar;
int progress;
private RelativeLayout rootView, afterAnimationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_activity);
    bookIconImageView = findViewById(R.id.logo);
    loadingProgressBar = (ProgressBar)findViewById(R.id.loadingProgressBar);
    rootView = findViewById(R.id.rootView);
    afterAnimationView = findViewById(R.id.afterAnimationView);
    Thread thred = new Thread(new Runnable() {
        @Override
        public void run() {
            doWork();
            startApp();
        }
        public void doWork() {
            for (progress=10;progress<100;progress=progress+10){
                try {
                    Thread.sleep(350);
                    loadingProgressBar.setProgress(progress);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }} }
        public void startApp(){
            runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  loadingProgressBar.setVisibility(GONE);
                                  rootView.setBackgroundColor(ContextCompat.getColor(SplashScreenActivity.this, R.color.splashscreen));
                                  bookIconImageView.setImageResource(R.mipmap.ic_launcher_round);
                              }
                          });
            startAnimation();
        };
});
    thred.start();
}


private void startAnimation() {
    ViewPropertyAnimator viewPropertyAnimator = bookIconImageView.animate();
    viewPropertyAnimator.x(50f);
    viewPropertyAnimator.y(100f);
    viewPropertyAnimator.setDuration(1000);
    viewPropertyAnimator.setListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            afterAnimationView.setVisibility(VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
}
// Intent myIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
//        SplashScreenActivity.this.startActivity(myIntent);
}

我有一个在登录屏幕之前显示的闪屏动画,我没有触及与 Java 中的文本输入框有关的任何内容,但也许我在某个地方犯了错误。

很可能您错过了添加应用程序级材料设计依赖项

// material Design support library - androidx
implementation 'com.google.android.material:material:1.0.0'


// material Design support library - support library
implementation 'com.android.support:design:28.0.0'

更新

您缺少在TextInputLayout添加TextInputEditText ,因此您不会期望看到某些内容,还将android:hintandroid:textSizeandroid:textColorHintandroid:textColor属性移动到TextInputEditText而不是TextInputLayout

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/emailEditText"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    app:boxBackgroundMode="outline">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email"
        android:inputType="textEmailAddress"
        android:textColor="@color/colorPrimary"
        android:textColorHint="@color/colorAccent"
        android:textSize="15sp" />

</com.google.android.material.textfield.TextInputLayout>

暂无
暂无

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

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