How to change Remote view Background in runtime

空扰寡人 提交于 2019-12-23 05:29:17

问题


I am trying to change the remote view background in runtime, I am using drawable xml to show customize notification.

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>

Drawable-->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>

Inside the activity

   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);
}

Please correct if am wrong. After trying to set shape color. am getting error "Unfortunately, App has been stopped" While receiving the notification

来源:https://stackoverflow.com/questions/24545857/how-to-change-remote-view-background-in-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!