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没有直接的经验,但我认为应该有某种自定义 Presenter。
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);
}
}
}
另一种简单的设置标题文本颜色的方法是在xml中覆盖leanback颜色:
<color name="lb_browse_header_color">#f00</color>
在您的主题中更改rowHeaderStyle
<style name="Header" parent="Widget.Leanback.Header"> <item name="android:textAppearance">@style/YourApperance</item> </style>
可能有点晚了,但是对于仍在寻找的人来说
<style name="AppTheme" parent="@style/Theme.AppCompat.Leanback">
<item name="rowHeaderStyle">@style/MediaHeader</item>
</style>
<style name="MediaHeader">
<item name="android:textAppearance">@style/MyMediaTextStyle</item>
</style>
<style name="MyMediaTextStyle">
<item name="android:fontFamily">@font/roboto</item>
<item name="android:textSize">30sp</item>
<item name="android:textColor">@android:color/white</item>
</style>