Keyboard android event?
In one of my classes I have two EditText
and a Button
on the bottom of the screen. When I select one of the EditText
s the keyboard appears. The problem is that then the EditText
and the Button
are moved to the front of the screen in order to see what you are writing. But, above the EditText
I have two TextView
and when I write something to the EditText
, the TextView
s disappears from the s开发者_高级运维creen.
Can I do something like this: when the user writes something in the Edittext
, only the EditText
moves up, and the rest aren't affected?
THis code animates your edtxt from top to bottom:
DO CHANGES ACCORDINGLY:
edtxt.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
TranslateAnimation slide = new TranslateAnimation(0, 0, -100,0 );
slide.setDuration(1000);
slide.setFillAfter(true);
edtxt.startAnimation(slide);
}
}
});
Add the android:windowSoftInputMode
attribute to your Activity
in the AndroidManifest
:
<activity android:name=".MyActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan">
</activity>
This will cause the screen to adjust correctly when the software keyboard opens.
You can overrite onConfigurationChanged method and check the keyboard up/down status
@Override
public void onConfigurationChanged(Configuration config)
{
super.onConfigurationChanged(config);
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)
{
}
else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
{
}
}
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
精彩评论