3

I use two applications. One exposes a RemoteView via an AIDL interface. The second uses a ListView and custom adapter to present the RemoteView.

With a very simple view with one layout and one TextView, the TextView is white in the Listview.

All applications use the same light style.

Is it possible to apply a style to a RemoteView ? Or, how it's possible to manage the style of a RemoteView instance ?

Thanks

Onur A.
  • 3,007
  • 3
  • 22
  • 37
Philippe Prados
  • 461
  • 3
  • 12

3 Answers3

1

RemoteView does not support changing themes. And then only way you can do is keep two layout files with same layout and different themes(like different font colors), and before you update appWidget, you can choose any one of the layouts as the RemoteView

Isaiah
  • 432
  • 2
  • 6
  • I reduce the problem to a very small application. `public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RemoteViews rv=new RemoteViews(MainActivity.class.getPackage().getName(),R.layout.provider1); ViewGroup vg=(ViewGroup)findViewById(R.id.remoteview); View v=rv.apply(this, vg); vg.addView(v); } }` activity_main.xml with a RelativeLayout and provider1.xml with a simple textview. But the textview generated with remoteview is white, not black. – Philippe Prados Sep 02 '13 at 14:33
  • 1
    @user1875107 Hi, Android RemoteView does not suppert multi theme which is supported by activity's normal layout. In you suituation, the only way is to keep two different layout for the remoteviews. – Isaiah Sep 03 '13 at 13:20
0

I solved this issue by creating one layout file for the RemoteView (in my case, I was creating a template for a custom notification) and two styles.xml files, one in values, another in values-v21. That way, I could apply the Material styles for Lollipop and up, and the normal styles for previous Android versions.

If you're trying to match a system style of some kind, you can take a look at the Android core system styles for a reference on how they're put together. I would especially look at attrs.xml since you can use some of those with the automatic theme syntax, e.g.

<style name="mediaNotificationTitle">
    <item name="android:textColor">?android:attr/textColorPrimary</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>

Then inside the layout, just refer to it with style=@style/mediaNotificationTitle.

Spoom
  • 168
  • 9
-1

It' possible to apply a style with a 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);
pprados
  • 1,127
  • 12
  • 21