Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android-tv Changing text color and font of browse fragment rows header

How to change text color and font of rows header in browse fragment?. The text not in menu but the text that appears above the rows.

like image 990
prit Avatar asked Nov 18 '15 07:11

prit


1 Answers

In addition to David's answer.

rowHeaderStyle applies the style both to menu items in HeaderFragment and row titles in RowFragment (these two fragments compose your BrowseFragment).

If you want their styles (font colors in particular) to be different, you can override BrowseFragment::onCreateHeadersFragment() and apply specific theme at that point.

1) Add these styles to styles.xml:

<style name="AppTheme.Leanback.Browse.Row" parent="@style/Theme.Leanback.Browse">
    <item name="rowHeaderStyle">@style/AppTheme.Leanback.Row</item>
</style>

<style name="AppTheme.Leanback.Browse.Header" parent="@style/AppTheme.Leanback.Browse.Row">
    <item name="rowHeaderStyle">@style/AppTheme.Leanback.Header</item>
</style>

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

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

2) Apply AppTheme.Leanback.Browse.Row theme to your activity in manifest.

3) Apply AppTheme.Leanback.Browse.Header theme to headers in your BrowseFragment:

// Kotlin snippet
override fun onCreateHeadersFragment() : HeadersFragment {
    class CustomHeadersFragment : HeadersFragment() {
        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
            return super.onCreateView(
                    inflater.cloneInContext(ContextThemeWrapper(inflater.context, R.style.AppTheme_Leanback_Browse_Header)),
                    container,
                    savedInstanceState
            )
        }
    }

    return CustomHeadersFragment()
}
like image 197
SqueezyMo Avatar answered Feb 05 '23 00:02

SqueezyMo