Android的电视,如何更改标题和headeritem的颜色的颜色?(Android TV, ho

2019-09-27 11:31发布

我想改变颜色行(GridItemPresenter)标题颜色(你好Android的电视!)和headeritem。

Answer 1:

要更改列表行标题风格,你必须使用自定义ListRowPresenter :

public class CustomListRowPresenter extends ListRowPresenter {
    public CustomListRowPresenter() {
        super();
        setHeaderPresenter(new CustomRowHeaderPresenter());
    }
}

public class CustomRowHeaderPresenter extends RowHeaderPresenter {
    @Override
    public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
        Presenter.ViewHolder viewHolder = super.onCreateViewHolder(parent);
        RowHeaderView rowHeaderView = (RowHeaderView) viewHolder.view;
        rowHeaderView.setTypeface(...);
        rowHeaderView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, ...);
        return viewHolder;
    }
}

还没有与任何BrowseFragment直接经验,但我希望有某种自定义演示者也。



Answer 2:

public class CustomListRowPresenter extends ListRowPresenter {
    public CustomListRowPresenter() {
        super();
        setHeaderPresenter(new CustomRowHeaderPresenter());
    }
}

class CustomRowHeaderPresenter extends RowHeaderPresenter {

    @Override
    public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
        HeaderItem headerItem = item == null ? null : ((Row) item).getHeaderItem();
        RowHeaderPresenter.ViewHolder vh = (RowHeaderPresenter.ViewHolder) viewHolder;
        TextView title = vh.view.findViewById(R.id.row_header);
        if(!TextUtils.isEmpty(headerItem.getName())) {
            title.setText(headerItem.getName());
            title.setTextColor(ContextCompat.getColor(FiosTVApplication.getAppContext(),
                    R.color.white));
            title.setTypeface(ResourcesCompat.getFont(title.getContext(), R.font.nhaasgroteskdsstd_bold));
            title.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
        }
    }
}


Answer 3:

另一种简单的方法来设置标题文字颜色是覆盖Leanback的颜色XML:

<color name="lb_browse_header_color">#f00</color>

优点/缺点:它设置颜色为所有头。



文章来源: Android TV, how to change color of title and color of headeritem?
标签: android-tv