亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問在fragment中oncreateview的參數viewGroup獲取的是什么?

請問在fragment中oncreateview的參數viewGroup獲取的是什么?

泛舟湖上清波郎朗 2022-06-10 11:07:36
我做自定義字體 項目使用了fragment 想用viewGroup遍歷設定自定義字體 我在oncreateview中嵌入了layout 試過oncreateview的參數viewgroup也確實不為空 可是也沒有子控件View view = inflater.inflate(R.layout.fragment_text,container);寫成這樣吧 確實是有子控件了但貌似是linearlayout之類的控件 不能獲得其中的子控件測試代碼 if (container.getChildCount()==0) {Log.e("Krislq", "container.getChildCount()=0");} else {Log.e("Krislq", "container.getChildCount()=not 0");//container.addView(view);test(container);}求實現 fragment 中用viewGroup遍歷設定自定義字體 的代碼……要是在配置文件中能寫個配置就解決就好了 我是設定指非系統自帶的字體……
查看完整描述

1 回答

?
慕俠2389804

TA貢獻1719條經驗 獲得超6個贊


 @Override        public View onCreateView(LayoutInflater inflater, ViewGroup container,                Bundle savedInstanceState) {            View rootView = inflater.inflate(R.layout.fragment_main_dummy,                    container, false);            if(rootView instanceof ViewGroup){                setAllTypeface((ViewGroup)rootView);            }            return rootView;        }         private void setAllTypeface(ViewGroup group) {            // TODO Auto-generated method stub            for(int i=0,j=group.getChildCount();i<j;i++){                View view = group.getChildAt(i);                if(view instanceof ViewGroup){                    setAllTypeface((ViewGroup)view);                }else if(view instanceof TextView){                    ((TextView)view).setTypeface(null);                }            }        }


查看完整回答
反對 回復 2022-06-14
  • 1 回答
  • 0 關注
  • 268 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號