在Android中修改远程布局的后台可绘制性

在Android中修改远程布局的后台可绘制性,android,android-layout,android-widget,drawable,remoteview,Android,Android Layout,Android Widget,Drawable,Remoteview,我有一个具有可绘制背景的小部件布局: <RelativeLayout android:id="@+id/basic_widget_layout" android:background="@drawable/basic_widget_style_2" android:clickable="true" > 我试图通过我的配置活动以编程方式调整@drawable/basic\u widget\u style\u 2,并在@+id/preview\u include

我有一个具有可绘制背景的小部件布局:

<RelativeLayout
    android:id="@+id/basic_widget_layout"
    android:background="@drawable/basic_widget_style_2"
    android:clickable="true" >
我试图通过我的配置活动以编程方式调整
@drawable/basic\u widget\u style\u 2
,并在
@+id/preview\u include
中查看实时结果

在我的配置活动中,我有启动我的特定appWidgetId,因此我的问题是-是否有可能获得属于启动我的活动的小部件的
@drawable/basic\u widget\u style\u 2

此外,如何使
-ed布局背景可绘制文件无效?
似乎无论我做什么,布局都是静态的(尝试使用invalidate()、refreshDrawable()和我见过的更多技巧)。

我无法理解您到底想在后台drawable中更改什么

为了获得视图的可绘制形状,您需要为包含形状的项目指定id,然后执行以下操作:

//change the color to the specific needed
LayerDrawable preview_include = (LayerDrawable)(this.findViewByID(R.id.preview_include)).getBackground();
final GradientDrawable preview_include_shape = (GradientDrawable)   include.findDrawableByLayerId(R.id.rectange);
例如,如果要更改形状的颜色,请执行以下操作:

        preview_include_shape.setColor(getResources().getColor(getResId("white", R.color.class)));
可使用该形状绘制的XML可能如下所示:

<?xml version="1.0" encoding="utf-8"?>


<?xml version="1.0" encoding="utf-8"?>
<!-- Up 2dp Shadow -->
<item >
    <shape  android:shape="rectangle">

        <solid android:color="@color/shadow" />
         <corners 
          android:radius="3dp"
             />
    </shape>
</item>

<!-- A rectange -->
<item android:top="3px" android:id="@+id/rectange">
    <shape android:shape="rectangle">
        <corners 
            android:topLeftRadius="3dp"
            android:topRightRadius="3dp"
            android:bottomLeftRadius="3dp"
            android:bottomRightRadius="3dp"/>
            <solid android:color="@color/black"
                    />
    </shape>
</item>