Android-动画发生后,键盘不会显示edittext
作者:互联网
我在这里看到了有关键盘未出现的问题/解决方案,但与我的特定问题无关.当您单击一个EditText时,键盘显示正常.但是,当我先为EditText设置动画时,然后当您单击EditText时,键盘将不会显示.
任何想法为什么会发生这种情况?
在“活动”中,我首先为徽标设置动画,然后完成动画设置,然后为EditTexts创建淡入动画.他们完成动画后,我尝试单击它们中的任何一个,但键盘不会出现.
这是我的Activity中的onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); //Remove title bar
setContentView(R.layout.login);
final EditText emailField = (EditText) findViewById(R.id.emailField);
final EditText passwordField = (EditText) findViewById(R.id.passwordField);
final TextView logInText = (TextView) findViewById(R.id.logInText);
final Button signupButton = (Button) findViewById(R.id.signupButton);
final Button loginButton = (Button) findViewById(R.id.loginButton);
//animation of logo
ImageView img_animation = (ImageView) findViewById(R.id.encoreLogo);
TranslateAnimation animation = new TranslateAnimation(0.0f, 00f,
0.0f, -400.0f);
animation.setDuration(4000);
animation.setFillAfter(true);
animation.setStartOffset(2000);
img_animation.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
Animation animFadeIn = AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in);
animFadeIn.setDuration(2000);
animFadeIn.setFillAfter(true);
emailField.setAnimation(animFadeIn);
passwordField.setAnimation(animFadeIn);
logInText.setAnimation(animFadeIn);
loginButton.setAnimation(animFadeIn);
signupButton.setAnimation(animFadeIn);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});
signupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, SignUpActivity.class);
MainActivity.this.startActivity(myIntent);
}
});
}
这是我对应的login.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/backroundImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:cropToPadding="false"
android:scaleType="centerCrop"
android:src="@drawable/crowdblur1" />
<ImageView
android:id="@+id/encoreLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:maxHeight="@dimen/thumbnail_height"
android:maxWidth="@dimen/thumbnail_width"
android:scaleType="centerInside"
android:src="@drawable/hand72" />
<TextView
android:id="@+id/logInText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/encoreLogo"
android:layout_alignLeft="@+id/passwordField"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_marginBottom="79dp"
android:paddingLeft="@dimen/left_padding_login_text"
android:text="Login to Encore"
android:textColor="@android:color/white"
android:textSize="@dimen/log_in_text"
android:textStyle="bold"
android:visibility="invisible" />
<EditText
android:id="@+id/emailField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/encoreLogo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:background="@drawable/rounded_corners"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="Email"
android:textColor="@android:color/black"
android:textStyle="italic"
android:visibility="invisible" />
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/encoreLogo"
android:layout_centerHorizontal="true"
android:background="@drawable/rounded_corners"
android:ems="10"
android:inputType="textPassword"
android:hint="Password"
android:textStyle="italic"
android:textColor="@android:color/black"
android:visibility="invisible" />
<Button
android:id="@+id/signupButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/loginButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="@android:color/transparent"
android:text="@string/signUp"
android:textColor="#5FC2FF"
android:textSize="@dimen/signupText"
android:textStyle="bold"
android:visibility="invisible" />
<Button
android:id="@+id/loginButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/passwordField"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:background="@android:color/transparent"
android:text="@string/login"
android:textColor="@android:color/white"
android:textSize="@dimen/signupText"
android:visibility="invisible" />
提前致谢!
解决方法:
如此看来,当您在EditText字段上将可见性设置为INVISIBLE时,它并不想获得焦点.
我通过在动画完成后更改这些字段的可见性来解决此问题:
animFadeIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
emailField.setVisibility(View.VISIBLE);
passwordField.setVisibility(View.VISIBLE);
logInText.setVisibility(View.VISIBLE);
loginButton.setVisibility(View.VISIBLE);
signupButton.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
});
希望这对您有所帮助:)
标签:android-edittext,android-animation,android 来源: https://codeday.me/bug/20191122/2059795.html