我创建的textinputlayout用于登录屏幕,但是每当启动活动时,除此以外的所有内容都会显示。单击应有的空间也无济于事(键盘没有弹出),因此,即使没有,可见性也已设置为“消失”。
布局文件:
<?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中的文本输入框没有任何关系,但也许我在那儿出错了。
答案 0 :(得分:1)
很可能您会错过添加应用程序级别的材料设计依赖项
// 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'
更新
您没有在TextInputEditText
中添加TextInputLayout
,所以您不会期望看到任何东西,还可以移动android:hint
,android:textSize
,android:textColorHint
和将android: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>