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 ?
-
Check and follow my answer below and let me know if you face any issue. – Jay Rathod Sep 09 '16 at 14:00
-
Have you tried my answer ? – Jay Rathod Sep 10 '16 at 07:02
3 Answers
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);

- 664
- 7
- 25
-
The *button* here didn't getting focus or not clickable while going to *Video Detail* screen ? Can you suggest workaround with that ? – Jay Rathod Dec 10 '18 at 07:11
-
You can do this using it's styles.xml
which is provided by Lean Back
library.
Follow the steps below first
.
Go to your
sdk
->extras
->android
->support
->v17
->leanback
->res
->values
.From there copy
styles.xml
file into your current leanback project folder.Now you have the
style.xml
file inside your project.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.

- 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
In other way,
It is possible to set using DetailsOverviewRowPresenter
like 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));
}

- 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