How to add multiple widgets in the same app?

后端 未结 5 1433
离开以前
离开以前 2020-11-28 02:04

I\'ve just finished my Android widget. Now I need to have different sizes of this widget for the user to choose from.

For example, I need a medium, small and large

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 02:16

    Ok so basically you will need:

    layout file fore each widget. ex: main_small.xml, main_medium.xml ...

    in the xml directory add a provider for each widget. ex: small_provider.xml, medium_provider.xml ... and so on (note if you don't have an xml directory add it under the drawable directory).

    now what!

    • define a receiver in the manifest for each widget. (just like the example in the main answer)

    • you can use the same layout or deferent layout. basically this is up to you.

    • in your provider you should have something like this:

    
    
    
    

    make sure, for each provider to specify the target layout file you want to use. in this code I'm asking for the file main.xml in the layout directory. for my medium widget for example i'll have another provider with the same exact code but i'll change the last line

    > android:initialLayout="@layout/medium".
    

    I hope this helps if not let me know and I can upload a working example on my website and you can take a closer look at it. please let me know how it goes.

    best of luck.

提交回复
热议问题