Hide part of activity_main.xml if keyboard is open (Android) -
i have following activity_main.xml shown @ bottom. there, coordinatorlayout
, 2 linearlayouts
occur. first linearlayout1 has edittext
input text, button send it. second 1 has 2 other buttons.
if click edittext
, keyboard shows , makes in linearlayout2 barely visible. so, want hide both buttons in last layout when keyboard open.
i found out use android:windowsoftinputmode="statehidden"
may trick, in connection activities in androidmanifest.xml
. want use inner second linear layout. tried use there, no success.
in addition, handle in xml , keep mainactivity-code clean. possibilities this?
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"> ... <android.support.design.widget.coordinatorlayout> <android.support.v7.widget.recyclerview/> </android.support.design.widget.coordinatorlayout> <linearlayout> <edittext/> <button android:id="@+id/button_send"/> </linearlayout> <linearlayout> <button/> <button/> </linearlayout> </linearlayout>
we had same issue in past have put observable on full layout object try , let me know
/*hide button when keyboard open*/ view.getviewtreeobserver().addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { rect r = new rect(); view.getwindowvisibledisplayframe(r); int heightdiff = view.getrootview().getheight() - (r.bottom - r.top); if (heightdiff > 244) { // if more 100 pixels, keyboard... //ok know keyboard up... buttonlayout.setvisibility(view.gone); } else { //ok know keyboard down... buttonlayout.setvisibility(view.visible); } } });
Comments
Post a Comment