use*_*928 8 xml android warnings comments
我收到警告,"此文本字段未指定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" />
Run Code Online (Sandbox Code Playgroud)
这样可以正常工作,只有在创建新的空白行时才会出现警告
我已经为一个朋友修改了它,有几个注释行解释了它的每个部分但是,每当我在上面添加一个额外的行时(即使是空行,在这种情况下它是注释行)我收到上面的错误
<!--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" />
Run Code Online (Sandbox Code Playgroud)
没有评论,警告不存在
小智 19
此警告的原因是您尚未为此editText设置inputType.添加以下行:
android:inputType="text"
Run Code Online (Sandbox Code Playgroud)
所以看起来应该是这样的:
<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" />
Run Code Online (Sandbox Code Playgroud)
警告消失了.
我只是运行你的代码并让我的应用程序正常运行,当我添加注释时它崩溃了,然后我意识到你不应该在 XML 中进行注释,这是 XML 的原则。
我建议您阅读这篇文章,解释什么是格式良好的 XML 以及如何以正确的方式注释 xml http://webdesign.about.com/cs/xmlinformation/ht/htcommentxml.htm 这里也有关于此的讨论特别是主题,也已经解决。
希望对您有帮助。