我需要做一个非常简单的事情 - 找出是否显示了软件键盘.这在Android中可行吗?
当软键盘处于活动状态并且我已成功实现它时,我已经研究了很多调整布局但是当我android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
在清单文件中的活动标签中使用它时问题就出现了.
为此,我使用android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"
了不同的选项,但没有运气.
之后,我以FullScreen
编程方式实现并尝试了各种布局,FullScreen
但都是徒劳的.
我引用了这些链接,并在此处查看了许多与此问题相关的帖子:
http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
http://davidwparker.com/2011/08/30/android-how-to-float-a-row-above-keyboard/
这是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/masterContainerView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff">
<ScrollView android:id="@+id/parentScrollView"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/setup_txt" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Setup - Step 1 of 3"
android:textColor="@color/top_header_txt_color" android:textSize="20dp"
android:padding="8dp" android:gravity="center_horizontal" />
<TextView android:id="@+id/txt_header" android:layout_width="fill_parent"
android:layout_height="40dp" android:text="AutoReply:"
android:textColor="@color/top_header_txt_color" android:textSize="14dp"
android:textStyle="bold" android:padding="10dp"
android:layout_below="@+id/setup_txt" />
<EditText android:id="@+id/edit_message"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Some text here." android:textSize="16dp"
android:textColor="@color/setting_editmsg_color" android:padding="10dp"
android:minLines="5" android:maxLines="6" android:layout_below="@+id/txt_header"
android:gravity="top" android:scrollbars="vertical"
android:maxLength="132" />
<ImageView android:id="@+id/image_bottom"
android:layout_width="fill_parent" android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud) Android中是否有任何方法可以在运行时获取Android设备的虚拟键盘的高度.其实我想在键盘上方显示文本框.
我想要的很简单,至少我认为这很简单.我只想要一个窗口,其中EditText位于屏幕的底部,其余的空间用ListView填充.不幸的是,它没有像我预期的那样工作.我想要的是下图.有没有简单的方法在XML中执行此操作,还是应该为此编写一些特殊代码?
我有问题的Android源代码.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/demolist"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
</ListView>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
</EditText>
</LinearLayout >
Run Code Online (Sandbox Code Playgroud) 我知道我可以使用"android:windowSoftInputMode ="adjustPan"做一些自动偏移.但我真的想得到一些特殊用途的软件键盘高度.
我发现这里有类似的话题:获得软键盘的尺寸.但显然,它不是一个通用的解决方案.
是否有通用方法或内置方法来获得软键盘高度?(或者如何获得当前光标位置和软件键盘顶部位置之间的偏移值?)
非常感谢
我有一个使用“adjustPan”作为其调整大小配置的活动,并且我需要计算键盘高度而不使用“adjustResize”,因为我需要将一些视图保留为全屏(这意味着它们应该保持在原来的位置,键盘应该隐藏它们),并将视图放置在键盘正上方。我们的应用程序有一个消息按钮,我通过单击按钮打开键盘。当发生这种情况时,我使用 OnGlobalLayoutListener 并使用“getWindowVisibleDisplayFrame”方法来获取键盘的高度。这是它的一些代码:
private void message()
{
InputMethodManager methodManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (methodManager != null && !isKeyboardOpen)
{
methodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
if (bottomCoordinate == 0)
{
RelativeLayout layout = findViewById(getFullScreenContainerId());
layout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Rect r = new Rect();
layout.getWindowVisibleDisplayFrame(r);
bottomCoordinate = r.bottom - r.top;
translateMessageView(bottomCoordinate);
}
});
}
else
translateMessageView(bottomCoordinate);
isKeyboardOpen = true;
}
}
Run Code Online (Sandbox Code Playgroud)
“translateMessageView”基本上将视图的 Y 坐标设置为“bottomCooperative - view.getHeight()”。在软键盘应用程序的自动更正部分变得可见之前,这种方法一直有效。显然,“getWindowVisibleDisplayFrame”方法似乎没有添加视图的自动更正部分,或者当软键盘的自动更正部分显示时,不会调用“onGlobalLayout”方法,并且定位的视图保留在其下方,这使其半可见。我需要能够再次调整它的位置,那么我该怎么办?正确的做法是什么?任何建议都很有价值,谢谢。