我尝试将自定义View
设为VerticalGridFragment
的标题
这是我创建的课程:
public class MainTitleView extends RelativeLayout implements TitleViewAdapter.Provider {
@BindView(R.id.top_logo)
ImageView topLogo;
private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() {
@Override
public View getSearchAffordanceView() {
return null;
}
@Override
public void setTitle(CharSequence titleText) {
MainTitleView.this.setTitle(titleText);
}
@Override
public void setBadgeDrawable(Drawable drawable) {
}
@Override
public void updateComponentsVisibility(int flags) {
}
};
public MainTitleView(Context context) {
this(context, null);
}
public MainTitleView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MainTitleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
View root = LayoutInflater.from(context).inflate(R.layout.main_title, this);
ButterKnife.bind(this, root);
topLogo.setImageResource(R.drawable.ic_logo_actionbar_white);
}
public void setTitle(CharSequence title) {
if (title != null) {
topLogo.setVisibility(View.VISIBLE);
}
}
@Override
public TitleViewAdapter getTitleViewAdapter() {
return mTitleViewAdapter;
}
}
然后在我的VerticalGridFragment
:
setTitleView(new MainTitleView(getActivity()));
这不起作用。我可以在调试器中看到构造函数被调用,但我看不到任何附加到标题的内容。我无法找到如何使用此TitleViewAdapter.Provider
的任何示例。
请帮忙。感谢。
答案 0 :(得分:1)
R.layout.custom_title
它为我工作。 @+id/browse_title_group
只是带有标识为options = {
"py2exe": {
"includes": ["pcapy"],
"excludes": [...],
"packages": [...],
...
}
}
的单一视图(com.your.company.MainTitleView)的xml。