我有一個WebView
,並在loadData
負荷iframe中。當softkeyboard出現 - 在Webview
變化的高度,但是當softkeyboard消失 - 在WebView
的高度不會改變。如何改變WebView的高度回到全屏?的WebView(與iframe中)沒有調整回來的時候softkeyboard消失
我的代碼:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.wbv);
webView.getSettings().setJavaScriptEnabled(true);
String html = "<html><body><iframe src=\"https://api.motion.ai/webchat/85714?color=EFB426&sendBtn=%D0%9E%D1%82%D0%B2%D0%B5%D1%82%D0%B8%D1%82%D1%8C&inputBox=%D0%9D%D0%B0%D0%BF%D0%B8%D1%88%D0%B8%D1%82%D0%B5%20%D0%B2%D0%B0%D1%88%20%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81%2F%D0%BE%D1%82%D0%B2%D0%B5%D1%82&token=9b32ca23536d9816b448d2e4c53434dc\" width="100%" height="100%"></iframe></body></html>";
webView.loadData(html,"text/html","UTF-8");
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.hr_bot.MainActivity">
<WebView
android:id="@+id/wbv"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
截圖:
編輯:
所以,現在我有這樣的事情:
final EKRAN myEkran = new EKRAN(MainActivity.this);
MAIN = findViewById(R.id.rootLayout);
MAIN.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
MAIN.getWindowVisibleDisplayFrame(r);
int screenHeight = MAIN.getRootView().getHeight();
int keypadHeight = screenHeight - r.bottom;
Log.d(String.valueOf(1) , "keypadHeight = " + keypadHeight);
if (keypadHeight > screenHeight * 0.10) { // 0.15 ratio is perhaps enough to determine keypad height.
// keyboard is opened
Toast.makeText(MainActivity.this , "COOL1 " , Toast.LENGTH_SHORT).show();
ViewGroup.LayoutParams params1 = webView.getLayoutParams();
params1.width = myEkran.W(100); // IN %
params1.height = myEkran.H(45); // IN %
webView.setLayoutParams(params1);
webView.requestLayout();
}
else {
Toast.makeText(MainActivity.this , "COOL2 " , Toast.LENGTH_SHORT).show();
// keyboard is closed
ViewGroup.LayoutParams params1 = webView.getLayoutParams();
params1.width = myEkran.W(100); // IN %
params1.height = myEkran.H(92); // IN %
webView.setLayoutParams(params1);
webView.requestLayout();
}
}
});
webView = (WebView) findViewById(R.id.wbv);
webView.getSettings().setJavaScriptEnabled(true);
String html = "<html><body><iframe src=\"https://api.motion.ai/webchat/85714?color=EFB426&sendBtn=%D0%9E%D1%82%D0%B2%D0%B5%D1%82%D0%B8%D1%82%D1%8C&inputBox=%D0%9D%D0%B0%D0%BF%D0%B8%D1%88%D0%B8%D1%82%D0%B5%20%D0%B2%D0%B0%D1%88%20%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81%2F%D0%BE%D1%82%D0%B2%D0%B5%D1%82&token=9b32ca23536d9816b448d2e4c53434dc\" width=\"100%\" height=\"100%\"></iframe></body></html>";
webView.loadData(html,"text/html","UTF-8");
@NikolaLukic我想它是一個WebView,因爲我爲它設置了自定義的背景顏色並在變形之後BG爲白色 –
使用類似下面:YOUR_CONTROL.getLayoutParams()高度=介紹runOnUiThread確保也在HTML內容。 –
重要提示:您需要使用FrameLayout(僅支持自定義位置 - 絕對)。 –