问题
I found something similar in SO: android-tv Changing text color and font of browse fragment rows header
Following topic answer I came up with this:
<style name="CustomRowHeaderStyle" parent="Widget.Leanback.Row.Header">
<item name="android:textColor">@color/red</item>
</style>
But this changes not only text that appears above the rows, but also navigation drawer text. I would love to get answer for the first one (having different color for navigation drawer item headers).
回答1:
if i understand your question correctly, you want to change color of row header presenter in browser fragment of android leanback library. for this purpose you can design header layout by your self to achieve this goal. first you need to design a custom android layout which lets call it custom_header_layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_view"
android:text="sample_text"/>
</FrameLayout>
then you need to make new class and extend ListRowPresenter to set your header layout to browserfragment like this:
public class MainListRowPresenter extends ListRowPresenter {
public MainListRowPresenter() {
setHeaderPresenter(new MainRowHeaderPresenter(R.layout.custom_header_layout));
}
@Override
protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) {
}
}
and then at last extends RowHeaderPresenter and to set data to your headers in browserfragment:
public class MainRowHeaderPresenter extends RowHeaderPresenter {
public MainRowHeaderPresenter(int layoutResourceId) {
super(layoutResourceId);
}
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
//do something hear
}
}
for more detail please check these two awesome post BrowseFragment Header customization and BrowseFragment ListRow customization.
hope this helps :)
来源:https://stackoverflow.com/questions/46198605/androidtv-change-color-of-rows-header-browsefragment