2020 0208 3 setContentView findViewById

3 篇文章 0 订阅
3 篇文章 0 订阅

2020 0208 setContentView

setContentView

原文

setContentView官方文档链接

android.support.v7.app.AppCompatActivity public void setContentView(@LayoutRes int layoutResID)

Description copied from class: android.app.Activity

Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.

Overrides: setContentView in class Activity

Params: layoutResID – Resource ID to be inflated.

总译

描述复制自类android.app.Activity。

设置布局资源中的活动内容。

传入的资源将会被填充,所有顶级视图都会加入到活动中。

重写:Activity类中的setContentView。

参数:layoutResID——用于填充的资源的ID。

findViewById

原文

android.support.v7.app.AppCompatActivity public <T extends android.view.View> T findViewById(@IdRes int id)

Description copied from class: android.app.Activity

Finds a view that was identified by the android:id XML attribute that was processed in onCreate.

Note: In most cases – depending on compiler support – the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.

Overrides: findViewById in class Activity

Params: id – the ID to search for

Returns: a view with given ID if found, or null otherwise.

总译

描述复制自类android.app.Activity。

查找要在onCreate方法中处理的视图,该视图由xml文件中android:id这一属性进行标识。

注意:在大多数情况下(取决于编译器的支持),查找到的结果视图类型会被强制转化为目标类类型,如果目标类类型是无约束的,那么可能需要进行显式强制转换。

重写:Activity类中的findViewById。

参数:id——要查找的视图的id。

返回:若找到则返回该id对应的视图,否则返回null。
findViewById官方文档链接

积累

cast to

强制转换,强制转化
cast
v. 浇铸;投;抛

compiler

n. 编译器;编译程序


参考学习自:
Android Studio 里的源码解释文档(鼠标划至相应代码自动调取英文释义)

另:
setContentView官方文档链接
findViewById官方文档链接


此文仅交流学习,与诸君共勉进步!
如有不当之处,望告知以便改进。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值