【问题标题】:Is it possible to set colors for a Swipe Refresh Layout in XML?是否可以在 XML 中为滑动刷新布局设置颜色?
【发布时间】:2021-02-21 03:15:41
【问题描述】:

我想在 XML 中设置适合主题的 ProgressBackgroundColorSchemeColorcolorSchemeColors 我的滑动刷新布局。 但是,我似乎只能找到以编程方式执行此操作的解决方案like this one below

TypedValue typedValue = new TypedValue();
int colorValue;
if (context.getTheme().resolveAttribute(R.attr.xxx, typedValue, true))
  colorValue = typedValue.data;
else
  colorValue = Color.TRANSPARENT;

mSwipeRefreshLayout.setColorSchemeColors(colorValue);

这些属性在 XML 中也无法识别;那有可能吗?

【问题讨论】:

    标签: android xml attr swiperefreshlayout


    【解决方案1】:

    每转一圈,箭头都会以每种颜色出现。

    mSwipeRefreshLayout.setColorSchemeResources(
      android.R.color.holo_blue_bright,
      android.R.color.holo_green_light,
      android.R.color.holo_orange_light,
      android.R.color.holo_red_light
    );
    

    【讨论】:

    • 这就像我引用的解决方案一样,只在运行时而不是在 XML 布局中设置颜色。我在我的问题中添加了mSwipeRefreshLayout.setColorSchemeColors(colorValue),因为我实际上并没有明确说明我使用什么方法来设置颜色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多