相关疑难解决方法(0)

Android:Dialog中的EditText不会拉起软键盘

所以我有一个似乎常见的问题,就是我的对话框中的EditText在获得焦点时不会显示出来.我已经看过几个解决方法,比如在这个帖子中,这一个这一个(还有更多),但我从来没有见过一个令人满意的解释,为什么这首先发生.

我更倾向于让Android使用自己的EditTexts默认行为,而不是构建我自己的行为,但似乎每个人(在那些线程中)已经接受了Dialogs中EditTexts的默认行为是只给光标而没有键盘.那为什么会这样?

为了记录,这些解决方法似乎都没有对我有用 - 我最接近的是强制键盘出现对话框下面(使用InputMethodManager.toggleSoftKeyboard(*)).我的特殊配置是API15,EditText显示在AlertDialog中ListView的页脚中.设置了EditText android:focusable ="true",onFocusChangeListener 正在接收焦点事件.

编辑:

根据要求,这是我正在使用的特定代码段.我不打算整个布局,但在这个特定的应用程序中,EditText响应于按下对话框上的按钮而出现(类似于动作视图).它包含在RelativeLayout中,默认情况下可见性"已消失":

 <RelativeLayout 
       android:id="@+id/relLay"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_centerVertical="true"
       android:visibility="gone"
       android:layout_marginTop="5dp"
       android:layout_marginBottom="5dp">

        <ImageButton
            android:id="@+id/cancelBut"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@color/transparent"
            android:src="@drawable/cancelButton" 
            android:layout_margin="5dp"/>

        <ImageButton
            android:id="@+id/okBut"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/cancelBut"
            android:background="@color/transparent"
            android:src="@drawable/okButton"
            android:layout_margin="5dp" />

        <EditText 
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:focusable="true"
            android:layout_toLeftOf="@id/okBut"/>
   </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

构建它的代码将relativeLayout的可见性设置为"Visible"(并隐藏其他UI元素).根据我使用EditText的经验,这应该足以在EditText聚焦时拉起键盘.但是,出于某种原因,情况并非如此.我可以在onFocusChangeListener上设置以下内容:

    edit_text.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                // For whatever reason we need to request …
Run Code Online (Sandbox Code Playgroud)

android dialog android-softkeyboard android-edittext

79
推荐指数
6
解决办法
4万
查看次数

在DialogFragment中使用适配器时,软键盘不显示

我有一个自定义的DialogFragment,里面有一个ArrayAdapter,里面有一些editTexts.显示对话框时,即使我按下编辑文本,也不会出现软键盘.编辑文本确实需要重点,但键盘永远不会出现.

如果我不使用适配器,只使用带有编辑文本的视图,它可以很好地工作,但只要我添加适配器,我就会遇到问题.

我的代码如下.任何帮助将非常感激.

提前致谢.

public class ParameterDialog extends DialogFragment {
Context context;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    ArrayList<Parameter> params = this.getArguments().getParcelableArrayList(MainActivity.KEY_PARAMS_TO_DIALOG);
    String name = this.getArguments().getString(MainActivity.KEY_NAME_TO_DIALOG);

    context = getActivity();
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ParameterDialogAdapter pda = new ParameterDialogAdapter(context,R.layout.parameter_config_string , params);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder
            .setTitle(name)
            .setAdapter(pda,null)
            .setPositiveButton("Send", new DialogInterface.OnClickListener() { …
Run Code Online (Sandbox Code Playgroud)

android android-arrayadapter android-dialogfragment

3
推荐指数
1
解决办法
1118
查看次数