Kur*_*rru 47 resources android
我正在从自定义xml视图类型中检索自定义资源ID.我被要求为检索指定一个默认的int值,并想知道ID的范围是多少?它们总是积极的还是包括零?
ie是一个有效的"null"引用AND/OR是0一个有效的"null"引用?
谢谢
编辑
自定义XML资源/属性文件
<resources>
<declare-styleable name="ToggleImageButton">
<attr name="onImage" format="integer" />
<attr name="offImage" format="integer" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
在我的自定义ui的构造函数中定义
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ToggleImageButton);
int offResource = a.getInt(R.styleable.ToggleImageButton_offImage, -1);
Run Code Online (Sandbox Code Playgroud)
基本上,第二行末尾的-1是此数据类型的默认参数.在开发时,它可能会也可能不会在XML视图中初始化,这允许以这种方式指定默认行为.
| 归档时间: |
|
| 查看次数: |
18030 次 |
| 最近记录: |