我在底部显示了以下 activity_main.xml.在那里,出现了一个 CoordinatorLayout 和两个 LinearLayouts.第一个 LinearLayout1 有一个 EditText 来输入一些文本,并带有一个按钮来发送它.第二个有另外两个按钮.
I have the following activity_main.xml shown at bottom. There, a CoordinatorLayout and two LinearLayouts occur. The first LinearLayout1 has an EditText to input some text, with a button to send it. The second one has two other buttons.
如果我点击 EditText,键盘会出现,并使 LinearLayout2 中的所有内容几乎不可见.所以,我想在键盘打开时隐藏最后一个布局中的两个按钮.
If i click into the EditText, the keyboard shows up and makes everything in LinearLayout2 barely visible. So, i want to hide both buttons in last layout when keyboard is open.
我已经发现使用 android:windowSoftInputMode="stateHidden" 可能是诀窍,但仅与 AndroidManifest.xml 中的活动有关.我只想在第二个线性布局中使用这个内部.已经尝试在那里使用它,但没有成功.
I already found out to use android:windowSoftInputMode="stateHidden" may be the trick, but only in connection with activities in AndroidManifest.xml. I just want to use this inner the second linear layout. Already tried to use it there, but with no success.
此外,我要在我的 xml 中处理这个问题并保持我的 MainActivity 代码干净.这有什么可能吗?
In addition, i what to handle this in my xml and keep my MainActivity-code clean. Any possibilities for 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>
我们过去也遇到过同样的问题,所以我们在完整布局对象上放置了一些 observable试试这个,让我知道
We had same issue in past so we have put some observable on full layout object try this and let me know
/*Hide button when keyboard is 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 than 100 pixels, its probably a keyboard...
//ok now we know the keyboard is up...
buttonLayout.setVisibility(View.GONE);
} else {
//ok now we know the keyboard is down...
buttonLayout.setVisibility(View.VISIBLE);
}
}
});
这篇关于如果键盘打开,则隐藏部分 activity_main.xml (Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Android 上的数字软键盘Numeric Soft Keyboard on Android(Android 上的数字软键盘)
带有软键盘和“返回"的 EditText按钮EditText with soft keyboard and quot;Backquot; button(带有软键盘和“返回的 EditText按钮)
在 Android 上的应用程序中内置自定义“键盘&quoCustom #39;Keyboard#39; built in an application on Android(在 Android 上的应用程序中内置自定义“键盘)
如何在 Android 的移动网站中强制使用带有数字的How to force keyboard with numbers in mobile website in Android(如何在 Android 的移动网站中强制使用带有数字的键盘)
启动 Activity 时自动弹出键盘Automatic popping up keyboard on start Activity(启动 Activity 时自动弹出键盘)
如何制作 Android EditView“完成"按钮并在单击时How do I make an Android EditView #39;Done#39; button and hide the keyboard when clicked?(如何制作 Android EditView“完成按钮并在单击时隐藏