I'm trying to change the color of a linearview when a certain state happens in my live card. I added the colors I want in my colors.xml and I'm able to set them in the live card layout itself.
but is there a way to set the background from code? I saw that there is no .setbackground or anything like this.
So is there a way to do this or would I need to go with images?
You can try to give the layout id in the xml and then:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.live_card);
remoteViews.setInt(R.id.my_layout, "setBackgroundResource", android.R.color.holo_red_dark);
mLiveCard.setViews(remoteViews);
// Display the options menu when the live card is tapped.
Intent menuIntent = new Intent(this, LiveCardMenuActivity.class);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.publish(PublishMode.REVEAL);
} else {
mLiveCard.navigate();
}
return START_STICKY;
}
xml:
<LinearLayout
android:id="@+id/my_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/card_margin"
tools:context=".LiveCardService">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>