我正在尝试在运行时更改远程视图背景,我使用drawable xml来显示自定义通知。
custom_notification.xml
android:background="@drawable/layout_bg"
android:layout_height="65sp"
android:padding="10dp" >
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:drawableLeft="@id/layout"
android:layout_marginRight="10dp" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:textColor="@color/white"
android:textSize="12sp"
style="Custom Notification Title" />
</RelativeLayout>
绘制对象 - &GT; layout_bg.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/shape">
<shape android:shape="rectangle">
<stroke android:width="3dip" />
<corners android:radius="10dip" />
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
</item>
</layer-list>
活动内部
View v = findViewById(R.id.layout);
LayerDrawable bgDrawable = (LayerDrawable)v.getBackground();
final GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.shape);
if(highstatus){
shape.setColor(R.color.highStatus);
}
如果错了,请更正。试图设置形状颜色后。我收到错误&#34;很遗憾,应用已停止&#34; 收到通知时