Android的 - 键盘不会出现的EditText动画后会发生 [英] Android - keyboard won't appear for edittext after animation happens

查看:174
本文介绍了Android的 - 键盘不会出现的EditText动画后会发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里看到的问题/解决方案的键盘显示不出来,但没有关于我的具体问题。当你点击一个EditText,键盘显示了罚款。但是,当我第一次动画的EditText,那么当你点击的EditText键盘不会出现。

I have seen questions/solutions here for the keyboard not showing up, but none relating to my specific issue. When you click an EditText, the keyboard shows up fine. But, when I animate the EditText first, then when you click the EditText the keyboard will NOT show up.

任何想法,为什么这可能发生?

Any ideas why this could be happening?

在我的活动我第一次动画我的标志,它完成动画后,我创建了一个淡入动画的EditTexts。他们完成了动画之后,我尝试点击其中的任何但键盘不会出现。

In my Activity I first animate my logo, and after it's done animating I create a fade-in animation for the EditTexts. After they finish the animation, I try and click any of them but the keyboard will not show up.

下面是我的onCreate方法在我的活动:

Here is my onCreate method in my Activity:

@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:

and here is my corresponding 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它不希望得到的焦点。

So it seems that when you have the visibility set to INVISIBLE on the EditText fields it doesn't want to get focus.

我的动画完成这样的后这些字段改变知名度修复了这个问题:

I fixed this issue by changing the visibility on those fields after the animation completes like this:

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) {}

});

希望这有助于你:)

Hope this helps you :)

这篇关于Android的 - 键盘不会出现的EditText动画后会发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆