安卓:编程创建的图像VS资源图片 [英] Android: programmatically created image vs resource image

查看:275
本文介绍了安卓:编程创建的图像VS资源图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)是否有可能创造绘,例如

1) Is it possible to create drawable, example

static Bitmap.Config conf = Bitmap.Config.ARGB_8888;
static Bitmap bmp = Bitmap.createBitmap(100, 100, conf);
// something draw
// eventually convert to DrawableBitmap

然后将其转换/ asiggn为/投放资源,在功能使用具有资源ID参数,如:

and then convert it / asiggn as / put in resource, to use in function with resource id param, like:

public void setWidgetLayoutResource (int widgetLayoutResId)

或结果
2)是它可以动态地画出改变R.drawable.something.bmp形象?

or
2) is it possible to dynamically draw to change image in R.drawable.something.bmp?

这一切都在setWidgetLayoutResource()小部件的颜色改变,任何颜色,不固定的混凝土资源的颜色

All this for change color of widget in setWidgetLayoutResource() to any color, not fixed as color of concrete resource

推荐答案

我自己的答案

此问题是相对于我的其他:的Andr​​oid preferenceScreen
而我做的是这样的:

This question is relative to my other: Android PreferenceScreen and I was do it in this way:

Col​​orLinesView.java

public class ColorLinesView extends View
{
    private static GradientDrawable gdDefault = new GradientDrawable();
    public static int fillColor;

    public ColorLinesView(Context context, AttributeSet attrs)
    {   super(context, attrs);
    }

    @Override protected void onDraw(Canvas cv) 
    {   
       gdDefault.setColor(fillColor);
       gdDefault.setCornerRadius(4);
       gdDefault.setStroke(2, 0xffbbbbbb);
       this.setBackgroundDrawable(gdDefault);
    }
}

color_lines_accesory.xml

<?xml version="1.0" encoding="utf-8"?>
<android.swp.ColorLinesView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/colorBoxLines"
 android:layout_width="52dp"
 android:layout_height="26dp"
 android:gravity="right"
 android:layout_marginRight="6dp" />

最后,而编程创建preferenceScreen,之后添加类preference一些preF

and finally while programmatically create PreferenceScreen, after add category preference "somePref":

ColorLinesView.fillColor = 0xff00ff00; // examply green
somePref.setWidgetLayoutResource(R.layout.color_lines_accesory);

和相同的两条线(新彩)在preferenceClickListener()的一些preF的范畴,用拾色器后变色。

and the same two lines (with new color) in OnPreferenceClickListener() for "somePref" category, after using color picker to change color.

结果:

在这里输入的形象描述

这篇关于安卓:编程创建的图像VS资源图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆