Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's EditText is hidden when the virtual keyboard is shown and a SurfaceView is involved

I have a simple user interface: an EditText should be located below a SurfaceView. I use a RelativeLayout to arrange these two views.

Now, when I tap on the EditText to open the virtual keyboard the SurfaceView slides up but the EditText is hidden and does not show the typed string.

To reproduce, use the following layout XML code:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout01"
android:layout_height="fill_parent" 
android:layout_width="fill_parent">

<SurfaceView
android:id="@+id/SurfaceView01"
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</SurfaceView>

<EditText 
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentLeft="true" 
android:layout_alignParentBottom="true" 
android:selectAllOnFocus="true"
android:textStyle="normal"
android:singleLine="true">
</EditText> 

</RelativeLayout>

The main Activity class only needs to show the layout. When I start the program and tap the EditText, the virtual keyboard appears but the EditText field is gone.

Maybe the RelativeLayout is causing the problems, but I don't know how to reproduce the same layout with another Layout class.

Any suggestions are welcome, I really appreciate your help.

Thanks.

Edit:

Here are two screenshots, one showing the EditText at the bottom without virtual keyboard, one with virtual keyboard but with no EditText. It is interesting to note that the SurfaceView and the EditText actually shift upward, the EditText just disappears. BTW this also happens to a button if it is next to the EditText.

EditText below a SurfaceView (left); EditText is gone (right)

like image 898
Jan Avatar asked Jun 04 '10 22:06

Jan


1 Answers

As a commenter in the thread about this bug suggested, it is very easy to fix this problem by setting the background color of the SurfaceView or GLSurfaceView to transparent with mSurfaceView.setBackgroundColor(Color.TRANSPARENT); as well.

This problem occurred for me when pressing an EditText on Honeycomb (v13) on a Samsung Galaxy Tab 10.1. The issue was that after the GLSurfaceView was resized, in its place was still a black rectangle which was covering the EditText. This solution works by making that erroneous rectangle transparent, so the EditText can be seen.

like image 127
Thomas Dignan Avatar answered Oct 10 '22 21:10

Thomas Dignan