在Android TV上的VerticalGridFragment上设置自定义标题

时间:2016-12-11 20:43:47

标签: android android-tv

我尝试将自定义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的任何示例。

请帮忙。感谢。

1 个答案:

答案 0 :(得分:1)

R.layout.custom_title

它为我工作。 @+id/browse_title_group只是带有标识为options = { "py2exe": { "includes": ["pcapy"], "excludes": [...], "packages": [...], ... } } 的单一视图(com.your.company.MainTitleView)的xml。