显示键盘的隐含意图

时间:2015-09-01 11:18:01

标签: android android-intent layout keyboard

我需要知道如何在没有显示TextView的情况下显示键盘,我曾想过使用Implicit Intents,但我没有看到任何示例。

我目前有这段代码: 对于布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".LoginActivity">

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:id="@+id/keyboardPassword"
    android:inputType="numberPassword|textPassword"
    android:visibility="visible"
    android:maxLength="4"
    android:textColor="@android:color/transparent"
    android:selectAllOnFocus="true"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/userListing"
    android:layout_weight="1"
    android:touchscreenBlocksFocus="true"
    android:longClickable="true"
    android:fastScrollEnabled="true"
    android:clickable="true"
    android:smoothScrollbar="true"
    android:divider="@android:color/black"
    android:dividerHeight="1.0sp"
    android:scrollingCache="true"
    android:layout_centerHorizontal="true"
    android:layout_above="@+id/keyboardPassword" /> 
</RelativeLayout>

上课:

private void showKeyboard() {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
            //getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        }

    });
}
private void registerKeyboardClickCallback() {
    final TextView keyboard = (EditText) findViewById(R.id.keyboardPassword);
    keyboard.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
                //action
            }
            return false;
        }
    });
}

使用此代码会显示TextView行,如果我隐藏textView,则键盘永远不会显示

谢谢!问候!

0 个答案:

没有答案