简体   繁体   English

如何使 EditText 视图在 Presentation(Duel Screen)中获得焦点和 SoftKeyboard 输入?

[英]How to make EditText view get focus and SoftKeyboard input in Presentation(Duel Screen)?

  1. I am using Android Presentation to present different contents between the dual screens.我正在使用 Android Presentation在双屏之间呈现不同的内容。
  2. My Plan is to making the external display to present an EditText view, the Android device's main screen to present SoftKeyboard and get EditText view focus to make the input.我的计划是让外部显示器呈现EditText视图,Android 设备的主屏幕呈现 SoftKeyboard 并获得EditText视图焦点以进行输入。

I try to use EditText.requestFocus() and InputMethodManager to open SoftKeyboard.我尝试使用EditText.requestFocus()InputMethodManager打开 SoftKeyboard。

PS: Do not tell me to use onKeyDown listener and TextView.append() PS:不要告诉我使用onKeyDown监听器和TextView.append()

public class MainPresentationFragment extends PresentationFragment {
private EditText textView3;

public MainPresentationFragment() {}

public static MainPresentationFragment newInstance(Context context, Display display){
    MainPresentationFragment mainPresentationFragment = new MainPresentationFragment();
    mainPresentationFragment.setDisplay(context, display);
    return mainPresentationFragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    textView3 = rootView.findViewById(R.id.editText3);
    textView3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        textView3.requestFocus();
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    }
return rootView;
}

SoftKeyboard can present on the main screen, but EditText cannot get input. SoftKeyboard 可以显示在主屏幕上,但EditText无法输入。

SoftKeyboard can present on the main screen, but EditText cannot get input. SoftKeyboard 可以显示在主屏幕上,但 EditText 无法输入。

Correct.正确的。 Presentation is output-only. Presentation仅用于输出。 There is no input.没有输入。

My Plan is to making the external display to present an EditText view, the Android device's main screen to present SoftKeyboard and get EditText view focus to make the input.我的计划是让外部显示器呈现 EditText 视图,Android 设备的主屏幕呈现 SoftKeyboard 并获得 EditText 视图焦点以进行输入。

You should be able to get something like that if:如果出现以下情况,您应该能够得到类似的结果:

Alternatively, you would need to use something like a TextWatcher on the main screen's EditText and duplicate the entered text onto the Presentation 's EditText .或者,您需要在主屏幕的EditText上使用类似TextWatcher东西,并将输入的文本复制到PresentationEditText This would be akin to the "onKeyDown listener and TextView.append()" approach that you seem to dislike.这类似于您似乎不喜欢的“onKeyDown 侦听器和 TextView.append()”方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示软键盘时如何在Android中获取Edittext输入类型 - How to get the Edittext input type in Android when softkeyboard is displayed 如何在滚动下面的视图时使EditText粘到屏幕顶部? - How to make EditText stick to top of screen while scrolling the view below it? 如何避免软键盘与片段中的 EditText 重叠? - How to avoid the softkeyboard overlapping the EditText in fragment? 我将视图膨胀了 5 次,膨胀的视图有一个 EditText,现在我在屏幕上有 5 个 EditText,如何从这些 EditTexts 中获取文本 - I inflated a view 5 times, the view which was inflated had a EditText, now i have 5 EditText on the screen, how to get the text from those EditTexts 使EditText从NumberPicker获得输入 - Make EditText get input from NumberPicker 如何根据日期输入(edittext)查看数据? - How to View data, based on date input(edittext)? 如何确保我的 EditText 始终具有焦点? - How can I make sure my EditText always has focus? 如何使按钮将EditText输入添加到Listview - How To Make Button Add EditText Input to a Listview Android-如果按键时EditText为空,如何隐藏软键盘? - Android - How to hide softkeyboard if EditText is empty on key press? Java如何从toggleSoftInput获取EditText的输入 - Java how to get input for EditText from toggleSoftInput
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM