Tag: drawable

Android:在运行时更改形状颜色

我有一个drawable,我用作LinearLayout的背景。 我想在运行时改变这个Shape的颜色。 我曾尝试使用几种方法..但没有工作。 我已经按照这里描述的方法: http : //www.anddev.org/android-2d-3d-graphics-opengl-problems-f55/change-shape-drawable-solid-color-t16798.html 但有同样的问题…它不会崩溃..但颜色不会改变! <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00A6C1" /> <corners android:radius="@dimen/square_corners" /> </shape> 代码片段: GradientDrawable drawable = (GradientDrawable) activity.getResources().getDrawable(R.drawable.blue_square_shape); int color = ((Application) getApplication()).getColor(); drawable.setColor(color); block.findViewById(R.id.blockSquare).setBackgroundDrawable(drawable); findViewById(R.id.blockSquare).postInvalidate(); 任何线索? 我已经通过了一整天的search…这是非常恼人的… 更新: 当我试图做同样的形状: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/shape" android:shape="rectangle"> <gradient android:startColor="#1FBCCF" android:endColor="#06A4C1" android:angle="270" /> <corners android:topLeftRadius="@dimen/footer_corners" android:topRightRadius="@dimen/footer_corners" /> </shape> 颜色变成黑色…我猜它可以改变…

Android的HTML ImageGetter作为AsyncTask

好的,我对这个失去了主意。 我在我的程序parsingHTML的方法。 我想包括内联图像,我的印象是使用Html.fromHtml(string,Html.ImageGetter,Html.TagHandler)将允许这种情况发生。 由于Html.ImageGetter没有实现,所以我写一个。 但是,由于将URLparsing为Drawables需要networking访问,因此我无法在主线程上执行此操作,因此它必须是AsyncTask。 我认为。 但是,当您将ImageGetter作为parameter passing给Html.fromHtml时,它将使用必须重写的getDrawable方法。 因此,无法调用触发doInBackground方法的整个ImageGetter.execute处理,因此无法真正实现这种asynchronous处理。 我是否完全错误,或者更糟的是,这是不可能的? 谢谢

setBackground vs setBackgroundDrawable(Android)

我想设置一个视图的可绘制背景。 有两种方法(据我所见): setBackground和setBackgroundDrawable 。 当我使用setBackground ,它说它已经被添加到API级别16中,但是我的项目的最小SDK版本是7.我认为它不会在16以下的任何东西上工作,对吗? 但是,当我使用setBackgroundDrawable,它说它已被弃用。 我该用什么?

了解使用ColorMatrix和ColorMatrixColorFilter来修改Drawable的色调

我正在为一个应用程序的UI工作,我试图使用灰度图标,并允许用户将主题更改为他们select的颜色。 要做到这一点,我试图只是应用某种ColorFilter覆盖绘制顶部的颜色。 我尝试过使用PorterDuff.Mode.MULTIPLY,它的工作原理几乎和我所需要的一样,只不过白色的颜色也覆盖了。 我最理想的东西就是Photoshop中的“颜色”混合模式,graphics保留其透明度和光度,并且只修改图像的颜色。 例如: 变 做了一些研究后,看起来ColorMatrixColorFilter类可以做我所需要的,但我似乎无法find指向如何使用matrix的任何资源。 这是一个4×5的matrix,但我需要知道的是我如何去devisematrix。 有任何想法吗? 编辑:所以没关系,到目前为止,我发现这个如下: 1 0 0 0 0 //red 0 1 0 0 0 //green 0 0 1 0 0 //blue 0 0 0 1 0 //alpha 这个matrix是单位matrix(应用时不作任何改变),数字范围从0到1(浮点数)。 该matrix将与每个像素相乘以转换为新的颜色。 所以这就是我开始模糊的地方。 所以我会认为每个像素将是一个1×4的向量,其中包含将与变换matrix点缀的argb值(例如0.2,0.5,0.8,1)。 所以要加倍图像的红色强度,可以使用如下matrix: 2 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 […]