简体   繁体   English

"AndroidTV - 更改行标题的颜色 [BrowseFragment]"

[英]AndroidTV - change color of rows header [BrowseFragment]

I found something similar in SO: android-tv Changing text color and font of browse fragment rows header我在 SO 中发现了类似的东西: android-tv 更改浏览片段行标题的文本颜色和字体

Following topic answer I came up with this:以下主题答案我想出了这个:

<style name="CustomRowHeaderStyle" parent="Widget.Leanback.Row.Header">
    <item name="android:textColor">@color/red</item>
</style>

But this changes not only text that appears above the rows, but also navigation drawer text.但这不仅会更改显示在行上方的文本,还会更改导航抽屉文本。 I would love to get answer for the first one (having different color for navigation drawer item headers).我很想得到第一个的答案(导航抽屉项目标题有不同的颜色)。

if i understand your question correctly, you want to change color of row header presenter in browser fragment of android leanback library. 如果我正确理解您的问题,您想在android leanback库的浏览器片段中更改行标题演示者的颜色。 for this purpose you can design header layout by your self to achieve this goal. 为此,您可以自行设计标题布局以实现此目标。 first you need to design a custom android layout which lets call it custom_header_layout 首先,您需要设计一个自定义的android布局,可以将其称为custom_header_layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text_view"
        android:text="sample_text"/>

</FrameLayout>

then you need to make new class and extend ListRowPresenter to set your header layout to browserfragment like this: 那么您需要创建新类并扩展ListRowPresenter以将标头布局设置为browserfragment,如下所示:

public class MainListRowPresenter extends ListRowPresenter {

    public MainListRowPresenter() {
        setHeaderPresenter(new MainRowHeaderPresenter(R.layout.custom_header_layout));
    }

    @Override
    protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) {

    }
}

and then at last extends RowHeaderPresenter and to set data to your headers in browserfragment: 然后最后扩展RowHeaderPresenter并将数据设置为浏览器片段中的标头:

public class MainRowHeaderPresenter extends RowHeaderPresenter {

        public MainRowHeaderPresenter(int layoutResourceId) {
            super(layoutResourceId);
        }

        @Override
        public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
             //do something hear
        }
   }

for more detail please check these two awesome post BrowseFragment Header customization and BrowseFragment ListRow customization . 有关更多详细信息,请检查以下两个很棒的帖子BrowseFragment Header自定义BrowseFragment ListRow自定义

hope this helps :) 希望这可以帮助 :)

<item name="rowHeaderStyle">@style\/header_style<\/item><\/code> in your main activity style <item name="rowHeaderStyle">@style\/header_style<\/item><\/code>在你的主要活动风格中

`  <style name="header_style">
     <item name="android:layout_marginStart">5dp</item>
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">@color/white</item>
</style>`

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

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