启动 Activity 时使 Android 小部件不可见

发布于 2024-11-17 18:57:34 字数 135 浏览 1 评论 0原文

我有一个小部件,当我单击它时,我正在开始具有透明背景的新活动,我想隐藏该小部件,以便只有该活动出现在主屏幕上,或者找到一种方法将活动窗口放在小部件的顶部,但我无法使用intent.getSourceBounds方法,因为我没有使用API​​级别7或更高版本

i have widget and when i click on it i'm starting new activity with transparent backround and i wanna hide that widget so only the activity is present on the homescreen or find a way to put the activity window on the top of the widget but i cant use intent.getSourceBounds method cause i'm not using API level 7 or above

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生来就爱笑 2024-11-24 18:57:34

如果您已使用以下代码

创建远程视图,请尝试使用以下代码

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);

示例,并使用以下代码设置整个小部件的可见性

views.setViewVisibility(R.id.widget_counter, View.INVISIBLE);

Try with the following code sample

if you have created Remote views using the following code

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);

set visibility of the whole widget using following code

views.setViewVisibility(R.id.widget_counter, View.INVISIBLE);
焚却相思 2024-11-24 18:57:34

我找到了解决方案

     public class homeWidget extends AppWidgetProvider {
public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
 @Override
    public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
    {
        RemoteViews remoteViews;
        ComponentName watchWidget;

        Intent active = new Intent(context, homeWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);


        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        watchWidget = new ComponentName( context, homeWidget.class );

        remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);



        appWidgetManager.updateAppWidget( watchWidget, remoteViews );
    }
 @Override
 public void onEnabled(Context context){
     AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
     RemoteViews remoteViews;
        ComponentName watchWidget;

        Intent active = new Intent(context, homeWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);


        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        watchWidget = new ComponentName( context, homeWidget.class );

        remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);

        mgr.updateAppWidget(watchWidget,remoteViews);

 }
 @Override
 public void onReceive(Context context, Intent intent) {
     AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
     if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
         Log.i("proverka", "uleva");
         Intent intent1 = new Intent(context,widget_activity.class);
         PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent1, 0);
         RemoteViews remoteViews;
         remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );

         ComponentName watchWidget;
         watchWidget = new ComponentName( context, homeWidget.class );

         remoteViews.setViewVisibility(R.id.LinearLayout01, View.GONE);
         try {
            pendingIntent.send();
        } catch (CanceledException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



         mgr.updateAppWidget(watchWidget,remoteViews);
         }
         super.onReceive(context, intent);
 }

 }

I found the solution

     public class homeWidget extends AppWidgetProvider {
public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
 @Override
    public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
    {
        RemoteViews remoteViews;
        ComponentName watchWidget;

        Intent active = new Intent(context, homeWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);


        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        watchWidget = new ComponentName( context, homeWidget.class );

        remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);



        appWidgetManager.updateAppWidget( watchWidget, remoteViews );
    }
 @Override
 public void onEnabled(Context context){
     AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
     RemoteViews remoteViews;
        ComponentName watchWidget;

        Intent active = new Intent(context, homeWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);


        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        watchWidget = new ComponentName( context, homeWidget.class );

        remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);

        mgr.updateAppWidget(watchWidget,remoteViews);

 }
 @Override
 public void onReceive(Context context, Intent intent) {
     AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
     if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
         Log.i("proverka", "uleva");
         Intent intent1 = new Intent(context,widget_activity.class);
         PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent1, 0);
         RemoteViews remoteViews;
         remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );

         ComponentName watchWidget;
         watchWidget = new ComponentName( context, homeWidget.class );

         remoteViews.setViewVisibility(R.id.LinearLayout01, View.GONE);
         try {
            pendingIntent.send();
        } catch (CanceledException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



         mgr.updateAppWidget(watchWidget,remoteViews);
         }
         super.onReceive(context, intent);
 }

 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文