Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

RelativeLayoutDetectKeyBoard

public class RelativeLayoutDetectKeyBoard extends RelativeLayout {

Rect rect = new Rect();
public RelativeLayoutDetectKeyBoard(Context context,
AttributeSet attrs) {
super(context, attrs);
}

public interface Listener {
public void onSoftKeyboardShown(boolean isShowing);
}

private Listener listener;

public void setListener(Listener listener) {
this.listener = listener;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
Activity activity = (Activity) getContext();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int screenHeight = activity.getWindowManager().getDefaultDisplay()
.getHeight();
int diff = (screenHeight - statusBarHeight) - height;
if (listener != null) {
listener.onSoftKeyboardShown(diff > 128); // assume all soft
// keyboards are at
// least 128 pixels high
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

}


This post first appeared on Android Training In Kerala, please read the originial post: here

Share the post

RelativeLayoutDetectKeyBoard

×

Subscribe to Android Training In Kerala

Get updates delivered right to your inbox!

Thank you for your subscription

×