本文介紹了將 EditText 定位在鍵盤上方的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有一個 EditText
看起來像這樣(帶有底部重力"):
I have got an EditText
looking like this (with "bottom gravity"):
當我按下 EditText
時,鍵盤會出現,我無法再看到我正在輸入的內容(因為 EditText 現在位于鍵盤后面,位于底部).按下鍵盤后,如何將 EditText
自動移動到鍵盤上方?
When I press the EditText
, the keyboard shows up and I can't see anymore what I'm typing (because the EditText is now behind the keyboard, on the bottom). How could I move the EditText
automatically just above the keyboard, when it has been pressed?
最后,如果它看起來像這樣就好了:
At the end, it would be good if it would look like this:
我的代碼:
// LINEAR LAYOUT
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);
// TEXTVIEW
layout.addView(tv);
// EDITTEXT
et.setGravity(Gravity.BOTTOM);
et.setInputType(InputType.TYPE_CLASS_TEXT);
et.setImeOptions(EditorInfo.IME_ACTION_SEND);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.BOTTOM;
et.setLayoutParams(params); // SOMETHING LIKE ONTOUCH -> MOVE UPWARDS
layout.addView(et);
推薦答案
在您的 Manifest 文件中為這個特定活動添加以下代碼
In your Manifest file add the following code for this particular activity
<activity android:windowSoftInputMode="adjustPan">
查看此文檔了解更多信息.
Check this doc for more info.
這篇關于將 EditText 定位在鍵盤上方的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!