开发者

Adview displaying on top of soft keyboard

I have just integrated AdWhirl into my app. I have the AdWhirl view set to show up on the bottom of the layout of my main activity. I have a few EditText boxes on my main layout and when the app first launches clicking开发者_Go百科 the text boxes displays the soft keyboard normally. However when I go to another activity and back to my main activity, then click the EditText the soft keyboard pops up with the AdWhirl view on top, covering my EditText box. I have been struggling with this for days. Any help would be appreciated.

I have android:windowSoftInputMode="adjustPan" defined in my manifest for all activities.

Here is my main.xml layout:

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

<ImageView android:id="@+id/ImageView02"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/other_bg_small" android:layout_weight="1"/>

<ImageView android:id="@+id/ImageView01"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:background="@drawable/banner" android:layout_alignParentTop="true" 
    android:paddingBottom="30dip"/>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:stretchColumns="1" android:gravity="center"        android:id="@+id/table01"
    android:layout_below="@id/ImageView01" >

     ... Table stuff
</TableLayout>

<LinearLayout android:layout_width="fill_parent"
    android:id="@+id/ad_layout" android:layout_height="wrap_content"
    android:gravity="bottom" android:layout_alignParentBottom="true"
    android:layout_alignBottom="@+id/RelativeLayout01" android:layout_weight="1">

    <com.adwhirl.AdWhirlLayout android:id="@+id/adwhirl_layout"
        android:layout_width="fill_parent" android:layout_height="wrap_content"/>

</LinearLayout>

 </RelativeLayout>


Try setting a onFocusChangeListener to your EditText boxes. When they get focus, set the AdWhirl view visibility to View.INVISIBLE so it doesn't obstruct the textboxes and then set it back to visible once focus is lost.

final AdWhirl ad = (AdWhirl)findViewById(R.id.adwhirlAd);
        EditText et = (EditText)findViewById(R.id.editTextBox);
        et.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                ad.setVisibility(hasFocus ? View.INVISIBLE : View.VISIBLE);

            }
        });


I tried setting android:windowSoftInputMode="adjustPan". it hides the adMob banner but also the EdiText. I also tried the accepted answer, but the edittext can get focus without the keyboard opens. So the solution I found is to hide the adMob banner when the keyboard opens. I learned how to detect if the keyboard opens here. and here is my solution:

final View activityRootView = findViewById(R.id.sample_main_layout);
            activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
                    if (heightDiff > Support.dpToPx(MainActivity.this, 200)) { // if more than 200 dp, it's probably a keyboard...
                        mAdView.setVisibility(View.GONE);
                    }
                    else{
                        mAdView.setVisibility(View.VISIBLE);
                    }
                 }
            });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜