2017-09-13 86 views
2

我發現類似的東西在SO:android-tv Changing text color and font of browse fragment rows headerAndroidTV - 行變色頭[BrowseFragment]

以下主題答案,我想出了這個:

<style name="CustomRowHeaderStyle" parent="Widget.Leanback.Row.Header"> 
    <item name="android:textColor">@color/red</item> 
</style> 

但這種改變不是上面僅顯示文本行,而且還有導航抽屜文字。我很想得到第一個答案(導航抽屜項目標題的顏色不同)。

回答

2

如果我正確理解您的問題,您想要更改android leanback庫的瀏覽器片段中的行標題演示者的顏色。爲此目的,您可以通過自己設計標題佈局來實現此目標。 首先你需要設計一個定製的Android的佈局,它可以讓調用它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> 

,那麼你需要做出新的類並擴展ListRowPresenter設置你的頭佈局browserfragment這樣的:

public class MainListRowPresenter extends ListRowPresenter { 

    public MainListRowPresenter() { 
     setHeaderPresenter(new MainRowHeaderPresenter(R.layout.custom_header_layout)); 
    } 

    @Override 
    protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { 

    } 
} 

然後最後擴展RowHeaderPresenter並將數據設置到瀏覽器片段中的標題:

public class MainRowHeaderPresenter extends RowHeaderPresenter { 

     public MainRowHeaderPresenter(int layoutResourceId) { 
      super(layoutResourceId); 
     } 

     @Override 
     public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { 
      //do something hear 
     } 
    } 

有關更多詳細信息,請檢查這兩個真棒帖子BrowseFragment Header customizationBrowseFragment ListRow customization

希望這有助於:)