marchemike
marchemike

Reputation: 3277

How to hide ImageView when keyboard is used on HTML WebView

I'm trying to hide my Imageview when I fill out some webforms that is being shown on my WebView. How can I force the Imageview to hide temporarily when it is shown? This is the form that I am using:

http://mytestwebsite.com/testform

<form action="sendData" method="POST">
<input type="text" id="data1" name="data1" />
</form>

The webView connects to a remote website with that form in it. Can I detect it in java so whenever the softkeyboard shows in this webpage, the imageview is automatically hidden?

this is my ImageView:

<WebView
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/relativeLayout1" />

<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:src="@drawable/footersuperlong" />

Is what I'm thinking possible or not?

Upvotes: 0

Views: 178

Answers (1)

Kirill Shalnov
Kirill Shalnov

Reputation: 2216

Look this about keyboard events.

snippet from there

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
    final int actualHeight = getHeight();

    if (actualHeight > proposedheight){
        // Keyboard is shown
    } else {
        // Keyboard is hidden
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

And about hiding. Just yourImageView.setVisibility(View.GONE); when you catch keyboard appearing and yourImageView.setVisibility(View.Visible); after disappearing.

View.GONE This view is invisible, and it doesn't take any space for layout purposes.

View.INVISIBLE This view is invisible, but it still takes up space for layout purposes.

Upvotes: 1

Related Questions