你是否正在寻找关于onfinishinflate的内容?让我把最完美的东西奉献给你:
要点:
1.定义Layout 文件 如header.xml
2. 继承类FrameLayout(或者ViewGroup, 或者View)
publicHeaderBar(Contextcontext,AttributeSetattrs){
this(context,attrs,R.style.headerTitleBarStyle);
}
publicHeaderBar(Contextcontext,AttributeSetattrs,intdefStyle){
super(context,attrs,defStyle);
LayoutInflater.from(context).inflate(R.layout.header,this,true);
TypedArraya=context.obtainStyledAttributes(attrs,R.styleable.HeaderBar);
mLeftButtonBg=a.getDrawable(R.styleable.HeaderBar_leftButtonBackground);
if(mLeftButtonBg==null){
mLeftButtonBg=context.getResources().getDrawable(R.drawable.back_btn_selector);
}
mRightButtonBg=a.getDrawable(R.styleable.HeaderBar_rightButtonBackground);
if(mRightButtonBg==null){
mRightButtonBg=context.getResources().getDrawable(R.drawable.refresh);
}
mTitleTextViewButtonBg=a.getDrawable(R.styleable.HeaderBar_titleTextViewBackground);
mTitle=a.getText(R.styleable.HeaderBar_title);
a.recycle();
}
3. 重载onfinishinflate来获取子控件的引用。
@Override
this.mTitleTextView.setBackgroundDrawable(this.mTitleTextViewButtonBg);
}
if(this.mTitle!=null){
this.mTitleTextView.setText(this.mTitle);
}
}
4. 如何使用?
在需要使用自定义控件的layout文件,以包名+控件名作为标签名
注意:如果需要用自己的属性,要加上自己的命名空间:xmlns:xl=http://schemas.android.com/apk/res/com.xxx.abc
规则是: + 包名
5. 如果你先在eclipse中预览, 千万要注意, 要重启Eclipse,Refresh 资源文件夹,。 不然会出现ResourceNotFound导致控件不能预览。
以上就是关于onfinishinflate的全部内容,相信你一定会非常满意。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-4744-1.html
虫子是绿色的标志