简体   繁体   English

如何从 BrowseFragment 中删除标题?

[英]How to remove headers from BrowseFragment?

I am working on an android TV app and I am using the leanback library.我正在开发一个 android 电视应用程序,我正在使用 Leanback 库。

I want to customize the app layout "BrowseFragment".我想自定义应用程序布局“BrowseFragment”。 I want to remove the header view and only display the card list "rows".我想删除标题视图,只显示卡片列表“行”。

Is it possible to do that or is there any other solution to achieve that?是否有可能做到这一点,或者有没有其他解决方案可以实现这一目标?

I want to remove that我想删除那个

The above call actually needs to be in the OnCreate method instead of OnActivityCreated.上面的调用实际上需要在 OnCreate 方法中,而不是在 OnActivityCreated 中。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHeadersState(HEADERS_DISABLED);
}

You have to set the HeaderState like this:您必须像这样设置 HeaderState:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHeadersState(HEADERS_DISABLED); // Add this line
}

There are two options:有两种选择:

/** The headers fragment is enabled and hidden by default. */

HEADERS_HIDDEN HEADERS_HIDDEN

/** The headers fragment is disabled and will never be shown. */

HEADERS_DISABLED HEADERS_DISABLED

OnCreate, you have to set the Header: OnCreate,你必须设置Header:

    setHeadersState(HEADERS_DISABLED); //To Diable the Header

    setHeadersState(HEADERS_HIDDEN); //To Hide the Header

When you change the setHeaderState(HEADERS_DISABLED), the rows would be disabled and hidden too.当您更改 setHeaderState(HEADERS_DISABLED) 时,这些行也将被禁用和隐藏。 One way to do it is setHeaderPresenterSelector()一种方法是 setHeaderPresenterSelector()

private void setupUIElements() {

    setHeadersState(HEADERS_DISABLED);

    setHeaderPresenterSelector(new PresenterSelector() {
        @Override
        public Presenter getPresenter(Object item) {
            return new CustomPresenter();
        }
    });
}

you just need to override the getPresenter() method, and return new customized presenter that you need to implement.您只需要覆盖 getPresenter() 方法,并返回您需要实现的新自定义演示器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM