1

I am using Leanback BrowseFragment and need to be able to set background colour of header item when selected. Any direct method/XML attributes available to do that? I have been looking into BrowseFragment and leanback themes.xml.

Reference: https://developer.android.com/reference/android/support/v17/leanback/app/BrowseFragment.html https://android.googlesource.com/platform/frameworks/support/+/master/v17/leanback/res/values/themes.xml

Lee Chun Hoe
  • 728
  • 11
  • 19
  • You may find a hints in here: http://stackoverflow.com/questions/33774150/android-tv-changing-text-color-and-font-of-browse-fragment-rows-header – Khairul Alam Licon Jul 20 '16 at 04:20
  • May be I also encounter the same case as you [http://stackoverflow.com/questions/43500898/how-to-rounder-corner-on-children-of-row-use-leanback-listrowpresenter](http://stackoverflow.com/questions/43500898/how-to-rounder-corner-on-children-of-row-use-leanback-listrowpresenter) – Toai Luong Apr 19 '17 at 16:32

1 Answers1

0

In my case I used custom header items with icons. You can see details in this tutorial. For TextView from my layout I defined xml file in the color directory, something like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/accent_color" android:state_selected="true"/>
<item android:color="@color/white"/>
</selector>

and the same xml files (but with android:drawable attributes ) in the direcroty drawable.

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/icon_focused"
     android:state_selected="true"/>
    <item android:drawable="@drawable/icon"/>
</selector>

Then simply set android:textColor="@color/your_new_xml_file" for TextViewand use your drawable files for your header ImageView.

If you need to change View background, not only header icon and text color, set such xml file with defined colors as a View background.

OnSelectLevelChanged() method in my presenter class is empty (without this, like in tutorial above) :

holder.view.setAlpha(mUnselectedAlpha + holder.getSelectLevel() *
                (1.0f - mUnselectedAlpha));
Jackky777
  • 644
  • 12
  • 19