我已经到了这一点,这让我在那里,但并不完全.我有一个拨号器Fragment,其中包含所有常用Button的输入数字,包括退格键,因此我不需要软键盘.我还想让用户能够粘贴文本(长按...默认情况下工作正常),以及编辑已输入的内容,因此我需要光标.
我找到的最简单的方法是确保软键盘不会弹出,如果用户点击内部EditText是设置inputType为null - 但这也会杀死光标.
那么,我如何声明我EditText应该启动哪些命令以使我的EditText字段永远不会显示软键盘,无论用户尝试什么,但仍然保留粘贴功能和光标?
我也尝试android:windowSoftInputMode="stateAlwaysHidden"过我的清单,但无济于事.
我正在使用 Jetpack Compose TextField,我想在用户按下操作按钮(imeActionPerformed参数)时关闭虚拟键盘。
val text = +state { "" }
TextField(
value = text.value,
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Done,
onImeActionPerformed = {
// TODO Close the virtual keyboard here <<<
}
onValueChange = { s -> text.value = s }
)
Run Code Online (Sandbox Code Playgroud) android android-input-method kotlin android-jetpack-compose android-compose-textfield
我有一个活动,其中有一个EditText,并在输入键搜索结果显示,所以我只想关闭键盘,当搜索结果即将显示,以防止用户必须这样做.但是,如果用户想要优化他的搜索,键盘应该打开,如果他再次点击EditText.
这比我想象的要困难得多,我一直在搜索并尝试了一些大多数甚至不关闭我的HTC键盘的东西,一种方法,其中InputType设置为INPUT_NULL关闭键盘,但之后不打开.
有关如何做到这一点的任何建议?
我正在尝试关闭在另一个应用程序中打开的软键盘.我从这里尝试了所有解决方案:以 编程方式隐藏/显示Android软键盘或此处:关闭/隐藏Android软键盘
正如你在图片中看到我必须关闭从另一个应用程序打开的键盘,添加到清单,不要让键盘可见不起作用.
要注意这是一个更衣室应用程序,我会在手机进入睡眠模式时启动一项活动.
我错过了什么吗?从商店测试其他更衣室应用程序并没有遇到此问题
但结果如下:

编辑:更多信息
这是我启动储物柜的方式:
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
//Toast.makeText(context, "" + "screeen off", Toast.LENGTH_SHORT).show();
wasScreenOn = false;
Intent intent = new Intent(context, LockScreenActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
// do whatever you need to do here
//wasScreenOn = false;
}
Run Code Online (Sandbox Code Playgroud)
这是清单代码:
<activity
android:name=".ui.activities.LockScreenActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
Run Code Online (Sandbox Code Playgroud) 每当我点击EditTextAndroid键盘弹出窗口出现,但我不想弹出键盘.
我想永久隐藏我当前应用程序的Android键盘弹出窗口.
我怎样才能做到这一点?
如何将ActionView(特别是SearchView)置于Action Bar的中心?
如Google图书应用中所示:
Google图书应用SearchView http://i46.tinypic.com/2z909is.png
我当前的布局设置(search_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<SearchView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="@string/search_hint" />
Run Code Online (Sandbox Code Playgroud)
我的Action Bar XML文件(menu.xml):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="@+android:drawable/ic_menu_search"
android:title="@string/search"
android:showAsAction="always|collapseActionView"
android:id="@+id/searchMenuItem"
android:actionLayout="@layout/search_layout" />
</menu>
Run Code Online (Sandbox Code Playgroud)
有没有办法模仿Books的SearchView的行为?
我有一个AutoCompleteTextView,它通常在用户输入3个字母后提供建议.一旦我触摸建议列表隐藏软键盘,我想要一次.我在下面使用表格布局所做的只有在点击建议列表时才会隐藏键盘.
XML
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<AutoCompleteTextView
android:id="@+id/auto_insert_meds"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textVisiblePassword|textMultiLine"
android:scrollHorizontally="false"
android:text=""
android:textSize="16sp" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
Java的
TableLayout tbl = (TableLayout) findViewById(R.id.main_table);
tbl.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
用于自定义列表的XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/medlist_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/med_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollHorizontally="false"
android:padding="3dp"
android:textColor="@android:color/white" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 对于某些EditText视图,我想使用自定义键盘而不是软键盘.
问题是当我EditText第一次点击一个键盘时显示.当我第二次点击时 - 软键盘终于消失了.
这种行为可能是什么原因?
这是我使用的代码:
package pkleczek.profiwan.keyboards;
import android.app.Activity;
import android.inputmethodservice.KeyboardView;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
public abstract class CustomKeyboard {
/** A link to the KeyboardView that is used to render this CustomKeyboard. */
protected KeyboardView mKeyboardView;
/** A link to the activity that hosts the {@link #mKeyboardView}. */
protected Activity mHostActivity;
/** Returns whether the CustomKeyboard is visible. */
public boolean isCustomKeyboardVisible() {
return …Run Code Online (Sandbox Code Playgroud) 我有一个活动,在屏幕上显示一些EditTexts用于用户输入.为了确保软键盘显示时我没有覆盖我的字段我已经设置了属性
android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud)
我在清单中的活动.我在1时验证EditText的内容.视图失去焦点2.当用户执行'Enter'操作时.验证后,如果该值无效,我正在打电话
setError(CharSequence error)
Run Code Online (Sandbox Code Playgroud)
在EditText上,这会导致弹出窗口显示包含我传入的错误.问题是如果在软键盘显示时向上移动EditText,并且此时显示弹出窗口(验证失败),弹出窗口没有当键盘离开时,请按下EditText,它将保持在首次显示的位置.
有想法该怎么解决这个吗?这是Android中的错误吗?
我正在为Android 3.1开发一个应用程序.有没有办法在全屏模式下显示(或强制)Android键盘?