现在的位置: 首页 > 综合 > 正文

Activity获取布局中的view,以及LayoutInfalter实例化

2018年04月04日 ⁄ 综合 ⁄ 共 507字 ⁄ 字号 评论关闭

用 Activity获取当前UI   layout中的 view

1,View view = findViewById(R.id.layout_id);

       layout_id为xml文件中指定的组件id.

2,View view =  mActivity.getWindow()
                .getDecorView().findViewById(android.R.id.content);

--------------------------------------------------------------------------------------

LayoutInfalter的获取方法

1. LayoutInflater inflater = mActivity.getLayoutInflater();

2. LayoutInflater inflater = LayoutInflater.from(context);

  
3. LayoutInflater inflater =  (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);

抱歉!评论已关闭.