Skip to content

Instantly share code, notes, and snippets.

@Krishan14sharma
Created July 30, 2015 07:32
Show Gist options
  • Save Krishan14sharma/677f9799accdcdccd775 to your computer and use it in GitHub Desktop.
Save Krishan14sharma/677f9799accdcdccd775 to your computer and use it in GitHub Desktop.
softkeyboard listner layout
package com.zapbuild.myi.ui.view;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class MyLayout extends LinearLayout {
public MyLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyLayout(Context context) {
super(context);
}
private OnSoftKeyboardListener onSoftKeyboardListener;
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
if (onSoftKeyboardListener != null) {
final int newSpec = MeasureSpec.getSize(heightMeasureSpec);
final int oldSpec = getMeasuredHeight();
if (oldSpec > newSpec){
onSoftKeyboardListener.onShown();
} else {
onSoftKeyboardListener.onHidden();
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public final void setOnSoftKeyboardListener(final OnSoftKeyboardListener listener) {
this.onSoftKeyboardListener = listener;
}
public interface OnSoftKeyboardListener {
public void onShown();
public void onHidden();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment