【问题标题】:Android Tv imageCardView background / extra contentAndroid 电视 imageCardView 背景/额外内容
【发布时间】:2014-09-19 12:53:17
【问题描述】:

对于 Android Tv 应用,我使用的是 v17 Leanback 库和 Leanback 主题。

在覆盖默认 imageCardView 背景颜色时遇到问题。

<!-- original styles defined in Leanback theme -->

<style name="Widget.Leanback.BaseCardViewStyle" />

<style name="Widget.Leanback.ImageCardViewStyle" parent="Widget.Leanback.BaseCardViewStyle">
    <item name="cardType">infoUnder</item>
    <item name="infoVisibility">activated</item>
    <!-- i want to override this  -->
    <item name="android:background">@color/lb_basic_card_bg_color</item>
</style>

<!-- In my styles.xml I inherit leanback theme and override imageCardViewStyle -->
<style name="AppTheme" parent="Theme.Leanback">
    <item name="imageCardViewStyle">@style/myImageCardViewStyle</item>
</style>

<style name="myImageCardViewStyle">
    <item name="cardType">infoUnderWithExtra</item>
    <item name="infoVisibility">activated</item>
    <item name="extraVisibility">activated</item>
    <!-- set new color  -->
    <item name="android:background">#FADCA7</item>
</style>

问题是背景颜色总是转换为 Leanback 主题中定义的“lb_basic_card_bg_color”,我不知道如何覆盖。

另外,我没有找到设置imageCardView额外卡片区域内容的方法。在 API 中,我只看到 setTitleText 和 setContentText 方法。

【问题讨论】:

  • 使用十六进制代码​​#FF6600
  • 我的colors.xml中定义了橙色
  • 好的,使用这个代码 ​​@android:color/orange
  • 获取颜色不是问题,编辑问题。

标签: android television


【解决方案1】:

如果您使用的是 Presenter(如 Leanback 演示中所示),您可以尝试访问与 ImageCardView 一起使用的 ViewHolder 并使用 findViewById 找到合适的 View。

试试这个:

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
    mContext = viewGroup.getContext();

    final ImageCardView imageCardView = new ImageCardView(mContext);
    imageCardView.setFocusable(true);
    imageCardView.setFocusableInTouchMode(true);
    imageCardView.findViewById(R.id.info_field).setBackgroundColor(mContext.getResources().getColor(YOUR_COLOR));

    return new ViewHolder(imageCardView);
}

Extra 是你用imageCardView.setBadgeImage(Drawable here);设置的ImageView

【讨论】:

    猜你喜欢
    • 2016-08-06
    • 2014-09-26
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多