Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TV: unfocused image contains black transparent background?

My Android TV app fetches images from a server and displays it on the home screen. The problem is, all the images that are not focused, i.e. not selected contains a black transparent background.

The only image that does not contain a transparent background is the currently selected image. I ensured that the images were pngs. As soon as the image is focused, the background is removed.

I'm not using a LinearLayout or anything in the .xml, just a GridItemPresenter class.

What is causing this and how can I fix this?

I tried to add the following view.setBackgroundColor(Color.TRANSPARENT) but that has no effect.

Here's my code:

private class GridItemPresenter extends Presenter
{
    public ViewHolder onCreateViewHolder(ViewGroup parent)
    {       
        ImageView view = new ImageView(parent.getContext());

        view.setBackgroundColor(Color.TRANSPARENT);

        view.setLayoutParams(new ViewGroup.LayoutParams((int)x, (int)y));
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
            return new ViewHolder(view);
    }

    public void onBindViewHolder(ViewHolder viewHolder, Object item)
    {
        ImageView imageView = ( (ImageView) viewHolder.view);

    }

    public void onUnbindViewHolder(ViewHolder viewHolder)
    {
        ImageView imageView = ( (ImageView) viewHolder.view);
    }
}

The face contains a black background when un-selected, but since it is selected, the background is not there: enter image description here

like image 387
Pangu Avatar asked Jul 14 '16 07:07

Pangu


1 Answers

I found a way to fix this. VertiGridPresenter's dimmer default is true , set it to false like:

VerticalGridPresenter gridPresenter = new VerticalGridPresenter(FocusHighlight.ZOOM_FACTOR_NONE, false);

or change the theme item <item name="overlayDimDimmedLevel">10%</item> in @style/Theme.Leanback, the percent value set the transparent value when set 100% the background will black.

like image 164
chinaanihchen Avatar answered Nov 16 '22 02:11

chinaanihchen