【问题标题】:EditText multiline, not editable but selectableEditText 多行,不可编辑但可选择
【发布时间】:2021-06-16 02:40:35
【问题描述】:

我需要一个多行EditText,用户只能选择和复制文本,但不能编辑它。

我试过这样:

<EditText
    android:id="@+id/editTextHelp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionNext"
    android:inputType="textMultiLine|none"
    android:textIsSelectable="true"
    android:minLines="3"
    android:maxLength="2000"
    android:scrollHorizontally="false" >
</EditText>

但是,textMultiLine|none 似乎不起作用。我怎样才能实现我想要的?

【问题讨论】:

    标签: android view android-edittext


    【解决方案1】:

    你可以用 TextView 代替

                    <TextView
                        android:id="@+id/editTextHelp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textIsSelectable="true"
                        android:focusable="true"
                        android:longClickable="true"/>
    

    【讨论】:

      【解决方案2】:

      如果只是为了显示一些文本,你应该使用 TextView 而不是 EditText,如下所示:

      <EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="none"
          android:textIsSelectable="true"/>
      

      但如果你想禁用文本输入并保持多行,也许你应该尝试像这样的编程方法:

          editText.setOnKeyListener(new View.OnKeyListener() {
              @Override
              public boolean onKey(View view, int i, KeyEvent keyEvent) {
                  return true;
              }
          });
      

      请阅读documentation了解更多信息

      【讨论】:

      • 多行在哪里?
      【解决方案3】:

      试试这个

       <EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="none"
          android:textIsSelectable="true"
          />
      

      【讨论】:

      • 多行在哪里?
      猜你喜欢
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2014-06-11
      • 2023-03-05
      • 2010-12-12
      • 1970-01-01
      相关资源
      最近更新 更多