可能重复:
Android:如何判断软键盘是否显示?
如何检测软键盘是否在屏幕上显示在android中?
在选择特定的EditText之前,如何防止软键盘消失?打开时,我的布局中有几个EditTexts,第一个自动选择并显示软件键盘.
我知道我可以通过设置android:focusable ="false"来禁用它.但是,无法点击该项目并显示该项目.
我想要的:活动开始,用户看到所有EditTexts,然后他点击一个,打开软件键盘,可以在EditText中输入内容.这可能吗?
我正在使用数据和时间选择器两个编辑文本,我想隐藏键盘两个编辑文本.我这样做
mDatePickerEdt = (EditText)findViewById(R.id.createwedding_datepicker_edt);
mTimePickerEdt = (EditText)findViewById(R.id.createwedding_timepicker_edt);
mDatePickerEdt.setInputType(InputType.TYPE_NULL);
mTimePickerEdt.setInputType(InputType.TYPE_NULL);
Run Code Online (Sandbox Code Playgroud)
它适用于智能手机.我在三星Galaxy笔记中遇到问题.如果有人有想法.请帮助,提前致谢.
我有一个自定义的EditText,用于输入一系列数字.我在类的构造函数中为它设置了DigitsKeyListener(getInputType()= 2).
这对Galaxy S(4.0)起到了"正确的作用".视图获得焦点时出现的键盘只有数字,"空格",句号,逗号,短划线,退格和"完成".
但是,在较旧的2.2设备上,出现的键盘上有字母和更宽范围的符号,这些都不是我需要的.
我在网上找到了一个建议:
setRawInputType(Configuration.KEYBOARD_12KEY);
Run Code Online (Sandbox Code Playgroud)
在初始化结束时.该值为"3".当我这样做时,两部手机的情况正好相反.Galaxy S上的键盘现在有字母(每个数字旁边,就像在手机上),而2.2设备上的键盘是我想要的(即基本上是计算器).
是否有一种统一的方法来获得适用于各种版本的"计算器"键盘,或者这是一种情况,我需要为SDK版本<= X做一件事,为版本> X做另一件事?
如果是这样,"X"的值应该是多少?这是一个特定的主要版本改变了吗?
我尝试过在线查找的各种方法来使用SDK中的softKeyboard示例.我尝试了几种不同的API.
我试过了 File -> New -> Other... -> Android Sample Project
我试过了 File -> New -> Other... -> Android Project from Existing Code
我尝试过创建一个新项目并复制文件
无论我做了什么,结果代码都会加载错误.例如:
还有更多.我已经得到了其他样品,没有问题.在导入这些样本时,我遗漏了一些东西.它是什么?
我已经尝试了平常但它不起作用:
multiEdit.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(multiEdit, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
注意我的getActivity().那是因为我MultiAutoCompleteTextView在DialogFragment中使用.片段在里面onCreateView.
keyboard android focus autocompletetextview android-softkeyboard
我想检查软件键盘是否可见.我读过这个 话题.
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是activityRootView.getRootView().getHeight()并且activityRootView.getHeight()始终返回相同的值,并不关心键盘是否可见.有什么想法吗?因为这个解决方案似乎适用于其他人.
我有一个奇怪的问题.在我的MainActivity工具栏中,我有一个动作搜索,这是我使用它的方式:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem searchItem = menu.findItem(R.id.search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(this);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(
new ComponentName(this, SearchableActivity.class)));
searchView.setIconified(false);
return true;
}
Run Code Online (Sandbox Code Playgroud)
但问题是,当我的应用程序启动时,键盘会弹出,甚至在我单击工具栏中的搜索按钮之前.我试图强制键盘隐藏在清单中我将其添加到我的MainActivity中:
android:windowSoftInputMode="stateAlwaysHidden"
Run Code Online (Sandbox Code Playgroud)
我甚至试过这个:
android:windowSoftInputMode="stateHidden"
Run Code Online (Sandbox Code Playgroud)
但他们的键盘仍然弹出.我没有任何EditText或任何我在MainActivity中只有图像和FAB的东西.
我有一个BottomSheetDialogFragment从另一个片段打开.
bottom_sheet_fragment.xml:
<LinearLayout>
<TabLayout/>
<ViewPager>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我有两个视图寻呼机片段,每个片段包含一个EditText和一个RecyclerView垂直方式.
view_pager_fragment1.xml:
<LinearLayout>
<EditText/>
<RecyclerView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在,当我点击编辑文本时,回收站视图的一部分隐藏在键盘后面.
预期: 当键盘出现时,底部表格应向上滚动,以便回收者视图内容保持可见.
android-layout android-softkeyboard android-fragments bottom-sheet
我有一个Bottomsheet片段,显示给用户回答他的评论.在底部的底部我们有编辑文本,用户可以在其中添加新评论.因此,当软键盘打开时,底部板位于键盘上方,其顶部远离屏幕.但是当键盘打开时,底部应该调整大小.
这是我的代码:
<android.support.design.widget.CoordinatorLayout
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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/toolbar_layout"
layout="@layout/partial_toolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list_comments"
android:layout_below="@+id/toolbar_layout"
android:layout_width="match_parent"
android:overScrollMode="always"
android:layout_height="match_parent"/>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_above="@+id/comment_container"
android:layout_alignBaseline="@+id/list_comments"
android:background="@drawable/elevation_bottom"/>
<LinearLayout
android:id="@+id/comment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ebffffff"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="@dimen/vertical_spacing"
android:paddingEnd="@dimen/horizontal_spacing"
android:paddingStart="8dp"
android:paddingTop="@dimen/vertical_spacing">
<android.support.v7.widget.AppCompatImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:src="@drawable/ic_add_blue_small"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_message_field"
android:gravity="center_vertical"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/transparent"
android:hint="@string/comments_add_comment_hint"
android:inputType="textMultiLine"
android:maxLength="200"
android:maxLines="3"
android:minLines="1"
android:paddingBottom="8dp"
android:paddingEnd="0dp"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:textSize="14sp"
app:fontFamily="@font/lora_regular"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/transparent"
app:srcCompat="@drawable/ic_send_message"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
清单上的活动(此活动打开对话框) …