android:id和android:labelFor之间的区别? [英] Difference between android:id and android:labelFor?

查看:1216
本文介绍了android:id和android:labelFor之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个具有EditText的简单布局,但它显示以下警告消息:

I wrote a simple layout which has an EditText, but it's showing the following warning message:

没有标签视图指向此文本字段"

"No label views point to this text field"

在搜索时,我发现了,它解决了该警告消息, 但两个属性android:idandroid:labelFor之间没有区别.有任何澄清吗?

While searching I found this and it solved that warning message, but did not get difference between both attributes android:id and android:labelFor. Any clarification?

推荐答案

android:id

为此视图提供一个标识符名称,以便以后使用 View.findViewById()Activity.findViewById().这一定是 资源参考;通常,您使用@ +语法将其设置为 创建一个新的ID资源.例如:android:id ="@ + id/my_id"其中 允许您以后使用findViewById(R.id.my_id)检索视图.

Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById(). This must be a resource reference; typically you set this using the @+ syntax to create a new ID resources. For example: android:id="@+id/my_id" which allows you to later retrieve the view with findViewById(R.id.my_id).

必须是对另一种资源的引用,格式为 "@[+][package:]type:name"或表单中的主题属性 ?[package:] [type:] name".

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

这对应于全局属性资源符号ID.

This corresponds to the global attribute resource symbol id.


android:labelFor

public static final int labelFor

指定该视图用作其标签的视图的ID 可访问性目的.例如,在 UI通常指定EditText中包含哪些信息. 因此,TextView是EditText的标签.

Specifies the id of a view for which this view serves as a label for accessibility purposes. For example, a TextView before an EditText in the UI usually specifies what infomation is contained in the EditText. Hence, the TextView is a label for the EditText.

必须为整数值,例如"100".

Must be an integer value, such as "100".

这也可能是对资源的引用(格式为 "@ [package:] type:name")或主题属性(格式为 ?[package:] [type:] name")包含此类型的值.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

常量值:16843718(0x010103c6)

Constant Value: 16843718 (0x010103c6)

更新:

例如-

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical">
    <LinearLayout android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_width="match_parent">
     <TextView android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:labelFor="@+id/edit_item_name" 
    android:text="Item Name"/>
     <EditText android:id="@+id/edit_item_name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="Item Name"/>
    </LinearLayout>
  </LinearLayout>

参考: android:id android:labelFor .

这篇关于android:id和android:labelFor之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆