2

enter image description hereHi Guys,

I want to change the color of default background color that comes on action button selection in details fragment.Any idea how the same can be acheived ?

prit
  • 643
  • 7
  • 21

3 Answers3

5

I didn't like the idea of copying the styles.xml into my own project. The way I did it was to just provide a custom presenter in the ArrayObjectAdapter constructor. When you don't supply a presenter, then a default one is inserted for you by the DetailsOverviewRow.

public class ActionPresenter extends Presenter {

  @Override public ViewHolder onCreateViewHolder(ViewGroup parent) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_action, parent, false);
    return new ViewHolder(v);
  }

  @Override public void onBindViewHolder(ViewHolder viewHolder, Object item) {
    Button button = (Button) viewHolder.view;
    Action action = (Action) item;

    button.setText(action.getLabel1());
  }

  @Override public void onUnbindViewHolder(ViewHolder viewHolder) {

  }
}

and the custom_action.xml

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:lines="1"
    android:paddingStart="10dp"
    android:paddingEnd="10dp"
    android:includeFontPadding="false"
    android:background="@drawable/action_selector"
    style="?android:attr/borderlessButtonStyle"
    />

Then in the details fragment you use it like any other adapter/presenter

ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter(new ActionPresenter());
    actionsAdapter.add(new Action(0, "Watch Now"));
    actionsAdapter.add(new Action(1, "More Info"));
    row.setActionsAdapter(actionsAdapter);
Redshirt
  • 664
  • 7
  • 25
4

You can do this using it's styles.xml which is provided by Lean Back library.

Follow the steps below first.

  1. Go to your sdk -> extras -> android -> support -> v17 -> leanback -> res -> values.

  2. From there copy styles.xml file into your current leanback project folder.

  3. Now you have the style.xml file inside your project.

  4. Open that file and find below style.

<style name="Widget.Leanback.DetailsActionButtonStyle" parent="Widget.Leanback.DetailsActionButtonStyleBase">

Inside that you can add below property and you will have it's background color changed.

<item name="android:background">@color/lb_speech_orb_recording</item>

I have tested this my side and it's working let me know if you face any issue.

Hope this will help you to get what exactly you need.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
  • So you are also adding all the dimens,string and drawables that leanback refers to ? – prit Sep 10 '16 at 19:58
0

In other way,

It is possible to set using DetailsOverviewRowPresenterlike this;

private void setupDetailsOverviewRowPresenter() {
    // Set detail background and style.
    DetailsOverviewRowPresenter detailsPresenter =
                new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
    detailsPresenter.setBackgroundColor(getResources().getColor(R.color.details_fragment_background_color));
}
alian
  • 204
  • 1
  • 12
  • this doesn't change the color of the action button. it only affects the background color of the bottom right element. – Dominik Mar 27 '19 at 12:53