I have set up the gradient in my drawable\\skycolor.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:endColor="#ff5bdddd"
android:startColor="#ff4688bf"
android:type="linear" />
</shape>
</item>
I want to set this gradient as the background of my homescreen widget. I already have an imageview placed in the widget.
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/iv_background"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:focusableInTouchMode="true" />
How do I set the gradient as the background color in the updateAppWidget method? Initially I planned to do it this way, but it did not work.
ImageView iv_skyColor = (ImageView)findViewById(R.id.iv_background);
iv_skyColor.setBackground(@drawable/skycolor);
findViewbyID does not work inside updateAppWidget method,
updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId)
also the code can not resolve @drawable/skycolor. How can I resolve this?
没关系,我设法使用它,
views.setImageViewResource(R.id.iv_background, R.drawable.skycolor);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.