我的布局中有一个EditText和一个Button.
在编辑字段中写入并单击后Button,我想隐藏虚拟键盘.我假设这是一段简单的代码,但我在哪里可以找到它的一个例子?
android soft-keyboard android-layout android-softkeyboard android-input-method
在使用软键盘的Android设备上,我希望防止在横向模式下出现全屏键盘编辑视图(如下所示)(即我只想看到软键盘本身和我后面的视图).
我假设这可以使用setExtractViewShown(false)方法on 来实现InputMethodService,但我无法访问此默认实例并且不想实现自定义输入方法.

编辑添加:输入的视图不是TextView(它是View一个自定义InputConnection实现),所以android:imeOptions="flagNoExtractUi"在这里不起作用.
我使用AlertDialog.Builder来创建一个输入框,使用EditText作为输入方法.
遗憾的是,虽然EditText处于焦点状态,但软键盘不会弹出,除非您再次明确触摸它.
有没有办法强迫它弹出?
我在(AlertDialog.Builder).show()之后尝试了以下内容.但无济于事.
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(input, InputMethodManager.SHOW_FORCED);
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
谢谢!!
我是Android原生开发的新手,我正在试图弄清楚如何自定义IME动作按钮.我查看了Google文档,但我发现很少有关于预期行为的信息.
从官方指南中我了解到可以使用以下属性配置键盘操作按钮:
但经过一些经验尝试后,我发现API级别15和下一个API级别之间存在不同的行为.
我已经设置了一个具有以下属性的简单EditText元素:
<EditText
...
android:imeOptions="actionGo"
android:imeActionLabel="Custom"
android:imeActionId="666"
android:inputType="text"/>
Run Code Online (Sandbox Code Playgroud)
我已经在纵向和横向模式下检查了不同API级别的效果.这是结果.
API级别15 - 4.0.3
在纵向模式下,键标签为Go,传递给回调方法的操作ID为2,因此与imeOptions设置相对应.
在横向模式下,键标签/ id为Go/2作为纵向模式,而输入区域中显示的按钮为Custom/666,相应于imeActionLabel和imeActionId属性.
API级别16,17和18 - 4.1.2,4.2.2和4.3
在纵向和横向模式下,键和按钮都显示为自定义标签,并绑定到666 id,忽略imeOptions属性.
这种行为的不匹配非常烦人,因为:
你知道如何在API 15和16+中获得这个吗?或者,如果有一种方法可以在API版本的所有(或至少部分)中获得一致的行为?
也许我在IME设置中遗漏了一些可以证明不同行为的东西......
非常感谢你!
我在SO上搜索了六个其他答案,但没有找到一个有效的答案.我只想在用户按下回车键时关闭软键盘.(相当于疯狂的iOS'resignKeyboard'调用.)在下面的代码中,不会调用onEditorAction方法.我在我的XML文件中设置了EditText视图,片段中的代码如下:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fragView = inflater.inflate(R.layout.fragment_encrypt2, container, false);
textField = (EditText) fragView.findViewById(R.id.textField);
textField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int actionId,
KeyEvent arg2) {
// hide the keyboard and search the web when the enter key
// button is pressed
if (actionId == EditorInfo.IME_ACTION_GO
|| actionId == EditorInfo.IME_ACTION_DONE
|| actionId == EditorInfo.IME_ACTION_NEXT
|| actionId == EditorInfo.IME_ACTION_SEND
|| actionId == EditorInfo.IME_ACTION_SEARCH
|| (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(textField.getWindowToken(), …Run Code Online (Sandbox Code Playgroud) android actionlistener android-softkeyboard android-input-method
我有一个使用这种布局的虚假对话框:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/containerPageConatiner">
<FrameLayout android:id="@+id/dialogHolder"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="15dp"
android:layout_gravity="center"
android:background="@drawable/panel_picture_frame_bg_focus_blue"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我<FrameLayout>根据打开的对话框放置一个片段- 控制Dialog的活动如下所示:
<activity
android:label="@string/app_name"
android:name=".activity.DialogActivity"
android:theme="@style/CustomTheme.Screen.Transparent"
android:windowSoftInputMode="adjustResize">
Run Code Online (Sandbox Code Playgroud)
不幸的是,当您单击对话框内的编辑文本时,不会进行大小调整.在windowSoftInputMode字面上没有什么区别的功能是一样的全景模式.
文档说"这当然只适用于具有可调整区域的应用程序,可以缩小以留出足够的空间",但不会告诉您"可调整区域"的含义,并让我认为在某种程度上我不喜欢Ť有一个可调整大小的面积?
如果有人知道什么事可以帮助我吗?
编辑
如此围绕对话框不会改变任何东西:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/containerPageConatiner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/dialogHolder"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="15dp"
android:layout_gravity="center"
android:background="@drawable/panel_picture_frame_bg_focus_blue"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
EDIT2
Scrollview作为父级也无济于事:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/containerPageConatiner"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/dialogHolder"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的应用程序来测试以下功能.当我的活动启动时,需要在软键盘打开的情况下启动它.
我的代码不起作用?!
我已经在清单中尝试了各种"状态"设置,并且在InputMethodManager(imm)的代码中尝试了不同的标志.
我已将该设置包含在AndroidManifest.xml中,并在唯一活动的onCreate中显式调用.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.android.studyIme"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".StudyImeActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
...主要布局(main.xml)......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:id="@+id/edit_sample_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hello"
android:inputType="textShortMessage"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
......和代码......
public class StudyImeActivity extends Activity {
private EditText mEditTextStudy;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud) 我想要按下软键盘的任何键.我不想在我的Activity中使用EditView或TextView,必须从我的Activity中的扩展View处理该事件.
我刚试过这个:
1)覆盖onKeyUp(int keyCode, KeyEvent event)Activity方法.这不适用于softkeybord它只是抓住几个硬键盘.
2)创建我的OnKeyListener并在我的视图中注册包含注册和工作的OnTouchListener.这与softkeyboar完全不兼容.
3)覆盖onKeyUp(int keyCode, KeyEvent event)View方法.如果我设置我的OnKeyListener,如果我没有设置它,这根本不起作用.
4)使用InputMethodManager对象调用方法showSoftInput并将其传递给我的View.这对于抬起键盘既不起作用,实际上我不得不打电话toggleSoftInput; 也没有抓住关键事件.
我只在模拟器中测试过,但我认为这已经足够了.为什么它如此复杂从键盘上取一个简单的键事件?
我的Android应用程序中有一个要求.我需要以编程方式下载并保存SD卡特定文件夹中的文件.我开发了源代码,这是
String DownloadUrl = "http://myexample.com/android/";
String fileName = "myclock_db.db";
DownloadDatabase(DownloadUrl,fileName);
// and the method is
public void DownloadDatabase(String DownloadUrl, String fileName) {
try {
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/myclock/databases");
if(dir.exists() == false){
dir.mkdirs();
}
URL url = new URL("http://myexample.com/android/");
File file = new File(dir,fileName);
long startTime = System.currentTimeMillis();
Log.d("DownloadManager" , "download url:" +url);
Log.d("DownloadManager" , "download file name:" + fileName);
URLConnection uconn = url.openConnection();
uconn.setReadTimeout(TIMEOUT_CONNECTION);
uconn.setConnectTimeout(TIMEOUT_SOCKET);
InputStream is = uconn.getInputStream();
BufferedInputStream bufferinstream = new …Run Code Online (Sandbox Code Playgroud) 有没有办法显示连接USB键盘的软件键盘(在我的情况下是RFID阅读器)?
我试图使用InputManager强制显示它(带有这些或类似的参数),但没有运气
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Run Code Online (Sandbox Code Playgroud)
重要提示 - 我知道状态/系统栏中有一个按钮可以显示它,但用户(Kiosk应用程序)看不到此按钮.
keyboard android kiosk-mode android-softkeyboard android-input-method