【问题标题】:Android Gradient drawable color changeAndroid Gradient 可绘制颜色变化
【发布时间】:2011-10-28 06:44:06
【问题描述】:

我在可绘制文件夹中有一个可绘制的形状。这是 XML 结构:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient 
        android:startColor="#4D0418" 
        android:centerColor="#5F031D"
        android:endColor="#7D0227" 
        android:angle="-90" />
</shape>  

现在我想在运行时的 java 代码中更改 startColor、centerColor、endColor。怎么可能改变?

【问题讨论】:

  • 你应该可以使用 Java 反射来做到这一点。

标签: android colors gradient shape


【解决方案1】:

很遗憾,没有 API 可以做到这一点。我会在未来的 Android 版本中添加一个。

【讨论】:

  • 有没有通过java代码重新创建总drawable而不使用任何XML?
  • 我创建了一个 GradientDrawable 来替代 。但是我怎样才能将它设置为任何形状?我应该为此使用 ShapeDrawable 吗?如果是,那么我如何将 GradientDrawable 设置为该 ShapeDrawable?
  • GradientDrawable 是 的替代品
  • GradientDrawable 似乎没有任何等效于 ShapeDrawable 的 setShaderFactory 方法 which can be used to create a gradient with more than just 3 colors。唔。 :-/
  • 这似乎在API 16
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-08
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-04
相关资源
最近更新 更多