我有一个小部件布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_view"
android:backgroundTint="@color/md_blue_500"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/widget_border_black">
</RelativeLayout>
我有这样一个drawable文件(widget_border_black.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/dark_gray"/>
<solid
android:color="#000000"/>
<corners
android:radius="10dp"/>
</shape>
Drawable可以为我绘制一些边框等等。而android:backgroundTint属性可以使用我提供的特定颜色来着色背景。
问题是,我想在adroid小部件中使用RemoteViews类以编程方式设置任何颜色。
RemoteViews views;
我可以设置:
views.setInt(R.id.my_view, "setBackgroundResource", R.drawable.widget_border_black);
它允许我拥有带边框的小部件,但没有我的特定背景颜色。同时我可以设置:
views.setInt(R.id.my_view, "setBackgroundColor", note.getColor());
它允许我设置小部件的背景颜色,但没有我的可绘制边框。
在小部件中,setBackgroundResource
和setBackgroundColor
两种方法不能同时使用!
因此,我想通过编程方式设置android:backgroundTint
属性值(并提供任何颜色值,而不仅仅是来自资源xml的一个蓝色值)。
android:backgroundTint="@color/md_blue_500"
问题在于RemoteViews类没有设置backgroundTint属性的方法(例如View类的setBackgroundTintList方法或其他方法)。我该如何解决这个问题?