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

用 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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章