Forked from faruktoptas/KeyboardSensitiveRelativeLayout.java
Created
March 27, 2017 08:16
-
-
Save livotov/a1178bc814f175b163531709a95927c4 to your computer and use it in GitHub Desktop.
A layout that detects Soft Keyboard is visible or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class KeyboardSensitiveRelativeLayout extends RelativeLayout { | |
private OnKeyboardShowHideListener listener; | |
public KeyboardSensitiveRelativeLayout(Context context) { | |
super(context); | |
} | |
public KeyboardSensitiveRelativeLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public KeyboardSensitiveRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
public KeyboardSensitiveRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |
super(context, attrs, defStyleAttr, defStyleRes); | |
} | |
public void setKeyboardListener(OnKeyboardShowHideListener listener) { | |
this.listener = listener; | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
final int proposedHeight = MeasureSpec.getSize(heightMeasureSpec); | |
final int actualHeight = getHeight(); | |
if (actualHeight != proposedHeight && listener != null) { | |
if (actualHeight > proposedHeight) { | |
listener.onKeyboardShowHide(true); | |
} else { | |
listener.onKeyboardShowHide(false); | |
} | |
} | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
} | |
public interface OnKeyboardShowHideListener { | |
void onKeyboardShowHide(boolean visible); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment