簡體   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