我使用两个应用程序。一种是通过AIDL接口公开RemoteView。第二个使用ListView和自定义适配器来表示RemoteView。
在一个具有一个布局和一个TextView的非常简单的视图中,TextView在Listview中是白色的。
所有应用程序都使用相同的灯光样式。
是否可以将样式应用于RemoteView?或者,如何管理RemoteView实例的样式?
谢谢
发布于 2013-08-30 20:35:10
RemoteView不支持更改主题。然后,您唯一能做的就是保留两个具有相同布局和不同主题(如不同字体颜色)的布局文件,并且在更新appWidget之前,您可以选择其中任何一个布局作为RemoteView
发布于 2015-03-16 21:16:21
我通过为RemoteView创建一个布局文件(在我的例子中,我正在为一个自定义通知创建一个模板)和两个styles.xml文件解决了这个问题,一个是values,另一个是values-v21。这样,我就可以应用棒棒糖和更高版本的材质样式,以及以前Android版本的普通样式。
如果你想匹配某种系统风格,你可以参考一下the Android core system styles,了解它们是如何组合在一起的。我将特别关注attrs.xml,因为您可以将其中一些与自动主题语法一起使用,例如
<style name="mediaNotificationTitle">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>然后在布局中,只需使用style=@style/mediaNotificationTitle引用它。
发布于 2013-09-04 15:43:02
可以应用带有RemoteView的样式。
final View view=remoteViews.apply(new ContextWrapper(mContext)
{
public Context createPackageContext(String packageName, int flags) throws NameNotFoundException
{
return new ContextWrapper(getBaseContext().createPackageContext(packageName, flags))
{
// Delegate the theme to the context
@Override
public Theme getTheme()
{
return mContext.getTheme();
}
};
}
}, parent);https://stackoverflow.com/questions/18532900
复制相似问题