軟鍵盤適配

2021-09-07 16:44:13 字數 3462 閱讀 7459

軟鍵盤有時會導致頁面布局體驗差,解決方法之一是最外層巢狀scrollview,馬馬虎虎,下面是最優解

public

class keyboardlayout extends

framelayout

public

keyboardlayout(context context, attributeset attrs)

public keyboardlayout(context context, attributeset attrs, int

defstyleattr)

public

void

setkeyboardlistener(keyboardlayoutlistener listener)

public

keyboardlayoutlistener getkeyboardlistener()

public

boolean

iskeyboardactive()

/*** 獲取輸入法高度**

@return

*/public

intgetkeyboardheight()

public

inte***ce

keyboardlayoutlistener

private

class keyboardonglobalchangelistener implements

viewtreeobserver.ongloballayoutlistener

mscreenheight =((windowmanager) getcontext().getsystemservice(context.window_service))

.getdefaultdisplay().getheight();

return

mscreenheight;

}@override

public

void

ongloballayout()

miskeyboardactive =isactive;

if (mlistener != null

) }

}}

<?

xml version="1.0" encoding="utf-8"

?>

<

com.maweiqi.recyclerview.keyboardlayout

xmlns:android

=""android:orientation

="vertical"

android:layout_width

="match_parent"

android:layout_height

="match_parent"

>

<

android.support.v4.widget.nestedscrollview

android:id

="@+id/scroll_view"

android:layout_width

="match_parent"

android:layout_height

="match_parent"

>

<

linearlayout

android:id

="@+id/ll_parent"

android:orientation

="vertical"

android:layout_width

="match_parent"

android:layout_height

="match_parent"

>

<

textview

android:layout_width

="match_parent"

android:layout_height

="200dp"

android:background

="#0000ff"

/>

<

edittext

android:id

="@+id/account"

android:layout_width

="match_parent"

android:layout_height

="match_parent"

/>

<

edittext

android:layout_width

="match_parent"

android:layout_height

="match_parent"

/>

<

button

android:layout_width

="match_parent"

android:layout_height

="wrap_content"

android:text

="確定"

/>

linearlayout

>

android.support.v4.widget.nestedscrollview

>

com.maweiqi.recyclerview.keyboardlayout

>

工具類

public

class

keyboardutil

private

view mchildofcontent;

private

nestedscrollview mscrollview;

private

relativelayout.layoutparams relativelayoutparams;

private keyboardutil(activity activity, int

viewid)

});}

private

void

possiblyresizechildofcontent() else

}/*** 獲取螢幕可顯示區域高度**

@return

*/private

intcomputeusableheight()

}

清單檔案配置

android:windowsoftinputmode="statealwayshidden|adjustresize"

activity呼叫

//

鍵盤不遮擋按鈕

private

void

setscroll()

});scroll.setonscrollchangelistener(

new nestedscrollview.onscrollchangelistener()

});}

開啟軟鍵盤

win32的話話,要是這幾個函式sipinfo shsipinfo sipsetinfo sipgetinfo net底下有個inputpanel設定他的enable就ok了。隱藏輸入面板 bool lowersip return fres 公升起輸入面板 bool raisesip void re...

關於軟鍵盤

1.editext獲得焦點後自動彈出軟鍵盤的呼叫方法 檢視edittext原始碼,找到editext的父類textview,在ontouchevent方法中找到如下 if touchisfinished istexteditable textisselectable the above condit...

軟鍵盤管理

安卓開發一般都需要進行軟鍵盤管理,常用操作老司機已為你封裝完畢,你可以用這份工具進行管理,具體可以檢視原始碼,現在為你開車,demo傳送門。openkeybord 打卡軟鍵盤 closekeybord 關閉軟鍵盤 timerhidekeyboard 通過定時器強制隱藏虛擬鍵盤 iskeybord 輸...