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

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