Поместите виджет в панель быстрого запуска - PullRequest
0 голосов
/ 16 июня 2020

Я сделал очень простой виджет (imageView + textView) размером 1 x 1 ячейка. На экране все работает нормально, но я не могу отбросить его на панели быстрого запуска (я думаю, это так, как вы это называете. Это место внизу экрана, которое отображается на всех страницах, где можно удалить 5 значков приложений in).

Я могу сбросить виджеты приложений 1 x 1 (контакты), но не мои.

Есть ли способ добиться успеха (разрешение? определенный размер? ...). Трудно найти хороший тег, когда не произносится английский sh произносится.

виджет java класс, называемый «сообщениями»

.png для imageViews имеет размер 125 x 222 пикселей.

У меня Q (android 10)

Xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialKeyguardLayout="@layout/messages"
    android:initialLayout="@layout/messages"
    android:minWidth="40dp"
    android:minHeight="40dp"
    android:previewImage="@drawable/ico_message_on"
    android:updatePeriodMillis="86400000"
    android:widgetCategory="home_screen|keyguard"></appwidget-provider>

Макет

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:padding="@dimen/widget_margin">

    <ImageView
        android:id="@+id/imageView_message_on"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ico_messages_on"
        android:visibility="visible"
        android:layout_margin="8dp"
        />
    <ImageView
        android:id="@+id/imageView_message_off"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ico_messages_off"
        android:visibility="invisible"
        android:layout_margin="8dp"
        />

    <TextView
        android:id="@+id/unreadSms"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="0dp"
        android:background="@drawable/round_red"
        android:text=" 1 "
        android:textColor="#FFFFFFFF"
        android:textSize="14sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/unreadSpam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:layout_marginEnd="0dp"
        android:background="@drawable/round_blue"
        android:text=" 1 "
        android:textColor="#FFFFFFFF"
        android:textSize="14sp"
        android:textStyle="bold" />

</RelativeLayout>

Манифест

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxxxxxxx.widget">
    <application
        android:allowBackup="true"
        android:icon="@drawable/ico_message_on"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <receiver android:name=".Messages">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/messages_info" />
        </receiver >
        <receiver android:name=".WidgetReceiver" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

и java .class

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.RemoteViews;

public class Messages extends AppWidgetProvider
{
    private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
    {
        final RemoteViews layoutMessages = new RemoteViews(context.getPackageName(), R.layout.messages);

        final Intent intentWidget = new Intent(context, WidgetReceiver.class);
        intentWidget.setAction("");
        intentWidget.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetId);
        final PendingIntent pendingIntentWidget = PendingIntent.getBroadcast(context, 0, intentWidget, 0);
        layoutMessages.setOnClickPendingIntent(R.id.imageView_message_on, pendingIntentWidget);
        layoutMessages.setOnClickPendingIntent(R.id.imageView_message_off, pendingIntentWidget);
        appWidgetManager.updateAppWidget(appWidgetId, layoutMessages);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
        for (int appWidgetId : appWidgetIds) {
            updateAppWidget(context, appWidgetManager, appWidgetId);
        }
    }

    @Override
    public void onEnabled(Context context) {}

    @Override
    public void onDisabled(Context context) {}
}

Спасибо за чтение.

С уважением.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...