当我修改教程代码的副本时,我得到警告“此文本字段未指定inputType或提示”(如下)

<EditText android:id="@+id/edit_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message"
    android:layout_weight="1" />

这可以正常工作,并且警告仅在创建新的空白行时出现

我已经为一个 friend 修改了它,并在其中添加了几行注释行,以解释其每个部分的作用,但是,每当我在上面添加多余的行时(即使是空行,在这种情况下,它也是注释行),我都会收到上述错误
<!--edit text creates a text input box-->
<EditText android:id="@+id/edit_message"
<!-- edit_message is a variable, defined in   strings.xml-->
<!-- determines the width of the textField, in this case 0dp means "however long the text is" IE: it will grow to fit however many characters the user types -->
    android:layout_width="0dp"
<!-- determines the height of the Text Field -->
    android:layout_height="wrap_content"
<!-- The hint is the default value for the text field, it calls on the variable edit_message defined in strings.xml-->
    android:hint="@string/edit_message"
<!-- Weight means how much the screen the text field can take up, in this case, the ratio is 1:1 so it can take up however much room is needed, However if a different variable also had the weight of 1, the ratio would be 1:2 and each could take up half the screen -->
    android:layout_weight="1" />

没有评论,警告就不存在

最佳答案

产生此警告的原因是您尚未设置此editText的inputType。添加以下行:

android:inputType="text"

所以它应该看起来像这样:
<EditText android:id="@+id/edit_message"
    android:inputType="text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message"
    android:layout_weight="1" />

警告不见了。

关于android - 此文本字段未指定inputType或提示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16970172/

10-10 20:17