• <legend id='jVNf3'><style id='jVNf3'><dir id='jVNf3'><q id='jVNf3'></q></dir></style></legend>

    <small id='jVNf3'></small><noframes id='jVNf3'>

    <tfoot id='jVNf3'></tfoot>

      • <bdo id='jVNf3'></bdo><ul id='jVNf3'></ul>
    1. <i id='jVNf3'><tr id='jVNf3'><dt id='jVNf3'><q id='jVNf3'><span id='jVNf3'><b id='jVNf3'><form id='jVNf3'><ins id='jVNf3'></ins><ul id='jVNf3'></ul><sub id='jVNf3'></sub></form><legend id='jVNf3'></legend><bdo id='jVNf3'><pre id='jVNf3'><center id='jVNf3'></center></pre></bdo></b><th id='jVNf3'></th></span></q></dt></tr></i><div id='jVNf3'><tfoot id='jVNf3'></tfoot><dl id='jVNf3'><fieldset id='jVNf3'></fieldset></dl></div>

      1. Android - 将 AppWidgets 添加到 Activity

        Android - adding AppWidgets to an Activity(Android - 将 AppWidgets 添加到 Activity)
          <tbody id='kMVqw'></tbody>

        1. <small id='kMVqw'></small><noframes id='kMVqw'>

            <legend id='kMVqw'><style id='kMVqw'><dir id='kMVqw'><q id='kMVqw'></q></dir></style></legend>
            <tfoot id='kMVqw'></tfoot>

              <i id='kMVqw'><tr id='kMVqw'><dt id='kMVqw'><q id='kMVqw'><span id='kMVqw'><b id='kMVqw'><form id='kMVqw'><ins id='kMVqw'></ins><ul id='kMVqw'></ul><sub id='kMVqw'></sub></form><legend id='kMVqw'></legend><bdo id='kMVqw'><pre id='kMVqw'><center id='kMVqw'></center></pre></bdo></b><th id='kMVqw'></th></span></q></dt></tr></i><div id='kMVqw'><tfoot id='kMVqw'></tfoot><dl id='kMVqw'><fieldset id='kMVqw'></fieldset></dl></div>
                <bdo id='kMVqw'></bdo><ul id='kMVqw'></ul>
                • 本文介绍了Android - 将 AppWidgets 添加到 Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最初的目标是将 Google 搜索小部件添加到活动的线性布局中.我需要包含它,就像它在启动器中显示和工作一样(这就是我需要能够添加小部件的原因).

                  我想在我的活动中添加小部件,而不必启动小部件选择器活动.我尝试过了:

                  1.直接指定一个整数 id(我总是得到 inflate 错误)

                  I would like to add widgets to my activity whithout having to launch the widget picker activity. I tried to:

                  1. directly specify an integer id (I always get inflate errors)

                  2.像这样获取 id:

                  2. get the id like this:

                    ComponentName cn = new ComponentName(getBaseContext(), "com.android.quicksearchbox.SearchWidgetProvider");
                    int[] ids = AppWidgetManager.getInstance(getApplicationContext()).getAppWidgetIds (cn);
                  

                  (数组始终为空)

                  这些都不起作用.

                  在此之后,我有了这段代码,以使用 ID(如果我从小部件选择器活动中获取 ID,它就可以工作):

                  After this I have this code, to use the ID (it works if I get the ID from the widget picker activity):

                      AppWidgetProviderInfo withWidgetInfo = AppWidgetManager.getInstance(getApplicationContext()).getAppWidgetInfo(appWidgetId);
                      AppWidgetHostView hostView = myWidgetHost.createView(getBaseContext(), appWidgetId, withWidgetInfo);
                      hostView.setAppWidget(appWidgetId, withWidgetInfo);
                      LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
                      ll.addView(hostView);
                  

                  我该怎么做?谢谢!

                  推荐答案

                  试试这个:

                  // APPWIDGET_HOST_ID is any number you like
                  appWidgetManager = AppWidgetManager.getInstance(this);
                  appWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID);
                  AppWidgetProviderInfo newAppWidgetProviderInfo = new AppWidgetProviderInfo();
                  
                  // Get an id
                  int appWidgetId = appWidgetHost.allocateAppWidgetId();
                  
                  // Get the list of installed widgets
                  List<AppWidgetProviderInfo> appWidgetInfos = new ArrayList<AppWidgetProviderInfo>();
                  appWidgetInfos = appWidgetManager.getInstalledProviders();
                  
                  for(int j = 0; j < appWidgetInfos.size(); j++)
                  {
                      if (appWidgetInfos.get(j).provider.getPackageName().equals("com.android.quicksearchbox") && appWidgetInfos.get(j).provider.getClassName().equals("com.android.quicksearchbox.SearchWidgetProvider"))
                      {
                          // Get the full info of the required widget
                          newAppWidgetProviderInfo = appWidgetInfos.get(j);
                          break;
                      }
                   }
                  
                  // Create Widget
                  AppWidgetHostView hostView = appWidgetHost.createView(this, appWidgetId, newAppWidgetProviderInfo);
                  hostView.setAppWidget(appWidgetId, newAppWidgetProviderInfo);
                  
                  // Add it to your layout
                  LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
                  ll.addView(hostView);
                  

                  编辑:

                  要绑定小部件 ID,即让小部件更新并响应用户交互,请参阅此处的解决方案:小部件在重新时不响应- 通过代码添加

                  To bind widget IDs, i.e. make widgets update and respond to user interaction, refer the solution here: Widgets don't respond when re-added through code

                  这篇关于Android - 将 AppWidgets 添加到 Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  script.sh: line 1: ./gradlew: No such file or directory on Jenkins(script.sh:第 1 行:./gradlew:Jenkins 上没有这样的文件或目录)
                  Arduino: using Serial and Software Serial with bluetooth module(Arduino:使用带有蓝牙模块的串口和软件串口)
                  Access native serial port on Android(在Android上访问本机串口)
                  Android: USB Communication Android lt;-gt; External Device(Android:USB通信Androidlt;-gt;外接设备)
                  Sending commands from a PC to an Android phone - via physical connection (USB, Serial, etc)(从 PC 向 Android 手机发送命令 - 通过物理连接(USB、串行等))
                    <tfoot id='FdwIb'></tfoot>
                    • <bdo id='FdwIb'></bdo><ul id='FdwIb'></ul>
                        <tbody id='FdwIb'></tbody>

                          <i id='FdwIb'><tr id='FdwIb'><dt id='FdwIb'><q id='FdwIb'><span id='FdwIb'><b id='FdwIb'><form id='FdwIb'><ins id='FdwIb'></ins><ul id='FdwIb'></ul><sub id='FdwIb'></sub></form><legend id='FdwIb'></legend><bdo id='FdwIb'><pre id='FdwIb'><center id='FdwIb'></center></pre></bdo></b><th id='FdwIb'></th></span></q></dt></tr></i><div id='FdwIb'><tfoot id='FdwIb'></tfoot><dl id='FdwIb'><fieldset id='FdwIb'></fieldset></dl></div>
                          <legend id='FdwIb'><style id='FdwIb'><dir id='FdwIb'><q id='FdwIb'></q></dir></style></legend>
                          • <small id='FdwIb'></small><noframes id='FdwIb'>