gpt4 book ai didi

android - 在 Android TV 上的 VerticalGridFragment 上设置自定义标题

转载 作者:行者123 更新时间:2023-11-29 01:13:55 24 4
gpt4 key购买 nike

我正在尝试将自定义 View 设置为 VerticalGridFragment 的标题

这是我创建的类:

public class MainTitleView extends RelativeLayout implements TitleViewAdapter.Provider {

@BindView(R.id.top_logo)
ImageView topLogo;

private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() {
@Override
public View getSearchAffordanceView() {
return null;
}

@Override
public void setTitle(CharSequence titleText) {
MainTitleView.this.setTitle(titleText);
}

@Override
public void setBadgeDrawable(Drawable drawable) {
}

@Override
public void updateComponentsVisibility(int flags) {
}
};

public MainTitleView(Context context) {
this(context, null);
}

public MainTitleView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public MainTitleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
View root = LayoutInflater.from(context).inflate(R.layout.main_title, this);
ButterKnife.bind(this, root);
topLogo.setImageResource(R.drawable.ic_logo_actionbar_white);
}

public void setTitle(CharSequence title) {
if (title != null) {
topLogo.setVisibility(View.VISIBLE);
}
}

@Override
public TitleViewAdapter getTitleViewAdapter() {
return mTitleViewAdapter;
}
}

然后在我的 VerticalGridFragment 中:

setTitleView(new MainTitleView(getActivity()));

这行不通。我可以在调试器中看到调用了构造函数,但我看不到任何附加到 header 的内容。我找不到有关如何使用此 TitleViewAdapter.Provider 的任何示例。

请帮忙。谢谢。

最佳答案

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(android.support.v17.leanback.R.layout.lb_vertical_grid,
container, false);
ViewGroup gridFrame = (ViewGroup) root.findViewById(android.support.v17.leanback.R.id.grid_frame);
installTitleView(inflater, gridFrame, savedInstanceState);
getProgressBarManager().setRootView(root);
return root;
}

@Override
public View onInflateTitleView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View title = inflater.inflate(R.layout.custom_title, parent, false);
//initialize your custom title view here
return title;
}

它对我有用。 R.layout.custom_title 只是带有 id @+id/browse_title_group 的单个 View (com.your.company.MainTitleView) 的 xml。

关于android - 在 Android TV 上的 VerticalGridFragment 上设置自定义标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41090962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com