{"id":1975,"date":"2022-11-25T18:00:46","date_gmt":"2022-11-25T10:00:46","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/1975.html"},"modified":"2022-11-25T18:00:46","modified_gmt":"2022-11-25T10:00:46","slug":"miui-widget%e9%80%82%e9%85%8d%e5%bb%ba%e8%ae%ae%e5%8f%8a%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/1975.html","title":{"rendered":"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b"},"content":{"rendered":"<h2 id=\"_0\">1.<span class=\"wpcom_tag_link\">MIUI<\/span> <span class=\"wpcom_tag_link\">Widget<\/span>\u5e03\u5c40<span class=\"wpcom_tag_link\">\u81ea\u9002\u5e94<\/span>\u65b9\u6848\u5efa\u8bae\u53ca\u793a\u4f8b<\/h2>\n<h3 id=\"_0_0\">1.1.\u6982\u8ff0<\/h3>\n<p>\u80cc\u666f\u89c1\uff1a\u300aMIUI\u5c0f\u90e8\u4ef6\u6280\u672f\u89c4\u8303\u4e0e\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e\u300b\u4e2d\u300c\u5c0f\u90e8\u4ef6\u6280\u672f\u89c4\u8303\u548c\u8981\u6c42\u300d\u7b2c\u516b\u9879\u3002<\/p>\n<p>\u672c\u6a21\u5757\u4ecb\u7ecd\u4e86\u5e38\u7528\u7684\u51e0\u7c7bWidget\u5e03\u5c40\u5b9e\u73b0\u81ea\u9002\u5e94\u7684\u65b9\u6848\u3002<\/p>\n<h3 id=\"_0_1\">1.2.\u65b9\u6848\u4e0e\u793a\u4f8b<\/h3>\n<h4>1.2.1.\u5feb\u6377<span class=\"wpcom_tag_link\">\u5361\u7247<\/span>\u7684\u81ea\u9002\u5e94\u65b9\u6848\u5b9e\u8df5<\/h4>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121125437.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121125437.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><\/figure>\n<p>\u5feb\u6377\u529f\u80fd\u5361\u7247\u4e2d\u6bcf\u4e2aicon\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u662f\u5728widget\u4e2d\u65e0\u6cd5\u83b7\u53d6\u5177\u4f53\u663e\u793a\u5927\u5c0f\uff0c\u56e0\u6b64\u5982\u679c\u53ea\u5199\u6b7b\u4e00\u5957\u5c3a\u5bf8\uff0c\u5728\u67d0\u4e9b\u6a21\u5f0f\u4e0b\uff0cicon\u4f1a\u663e\u793a\u4e0d\u5168\u3002<\/p>\n<p>\u76ee\u524d\u91c7\u7528\u7684\u65b9\u6848\u662f\uff0c\u4f7f\u75282\u5957\u5e03\u5c40\u8d44\u6e90\uff0c\u5728\u5e03\u5c40\u4e2d\u5199\u6b7b\u5927\u5c0f\uff0c\u6839\u636eGoogle\u5c0f\u90e8\u4ef6\u5f00\u53d1\u6307\u5357\u4e2d\u63d0\u5230\u7684\uff0c\u4f7f\u7528OPTION_APPWIDGET_MIN_WIDTH\u6216\u8005OPTION_APPWIDGET_MAX_WIDTH\u8fd4\u56de\u7684\u6570\u503c\u51b3\u5b9a\u4f7f\u7528\u54ea\u5957\u5e03\u5c40\uff1a<\/p>\n<p>\u5148\u5b9a\u4e492\u5957\u4e0d\u540c\u5c3a\u5bf8\u7684layout\u8d44\u6e90\uff1a<\/p>\n<pre class=\"wp-block-code\"><code><em>\/\/layout_shortcut_large<\/em>\n&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:orientation=\"vertical\"&gt;\n\n    &lt;ImageView\n        android:id=\"@+id\/shortcut_icon\"\n        android:layout_width=\"53dp\"\n        android:layout_height=\"53dp\"\n        android:layout_gravity=\"center\"\n        android:scaleType=\"centerCrop\" \/&gt;\n\n    &lt;TextView\n        android:id=\"@+id\/shortcut_name\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"center\"\n        android:layout_marginTop=\"@dimen\/dp_4\"\n        android:textSize=\"24sp\" \/&gt;\n&lt;\/LinearLayout&gt;\n\n\n<em>\/\/layout_shortcut_small<\/em>\n&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:orientation=\"vertical\"&gt;\n\n    &lt;ImageView\n        android:id=\"@+id\/shortcut_icon\"\n        android:layout_width=\"28dp\"\n        android:layout_height=\"28dp\"\n        android:layout_gravity=\"center\"\n        android:scaleType=\"centerCrop\" \/&gt;\n\n    &lt;TextView\n        android:id=\"@+id\/shortcut_name\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"center\"\n        android:layout_marginTop=\"@dimen\/dp_4\"\n        android:textSize=\"14sp\"\/&gt;\n&lt;\/LinearLayout&gt;<\/code><\/pre>\n<p>\u5728\u4ee3\u7801\u4e2d\u52a8\u6001\u5224\u65ad\u4f7f\u7528\u54ea\u4e00\u5957\u5e03\u5c40\uff1a<\/p>\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> <strong>SimpleWidgetProvider<\/strong> : <strong>AppWidgetProvider<\/strong>() {\n\n    override fun <strong>onUpdate<\/strong>(\n    context: Context,\n    appWidgetManager: AppWidgetManager,\n    appWidgetIds: IntArray) {\n        appWidgetIds.forEach { appWidgetId -&gt;\n        updateAppWidget(context, appWidgetManager, appWidgetId)\n        }\n    }\n\n    fun <strong>updateAppWidget<\/strong>(\n        context: Context,\n        appWidgetManager: AppWidgetManager,\n        appWidgetId: Int,\n    ) {\n        val appWidgetManager = AppWidgetManager.getInstance(context)\n        val options = appWidgetManager.getAppWidgetOptions(appWidgetId)\n        <strong>if<\/strong> (options == <strong>null<\/strong>) {\n            <strong>return<\/strong> <strong>null<\/strong>\n        }\n        val minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)\n        val widgetLayoutRes = <strong>if<\/strong> \uff08minWidth &gt;= 300\uff09R.layout.layout_shortcut_large <strong>else<\/strong> R.layout.layout_shortcut_small\n        val remoteViews = RemoteViews(context.packageName, widgetLayoutRes)\n        appWidgetManager.updateAppWidget(appWidgetId, remoteViews)\n    }\n    \n    <em>\/**\n     * \u4efb\u4f55option\u7684\u66f4\u6539\u90fd\u4f1a\u89e6\u53d1,\u65e0\u6cd5\u901a\u8fc7newOptions\u6765\u5224\u65ad\u662f\u5426\u662f\u5927\u5c0f\u53d1\u751f\u4e86\u53d8\u5316\n     * \u9700\u8981\u5c06\u672c\u6b21\u7684MAX_HEIGHT\/MAX_WIDHT\u8bb0\u5f55\u4e0b\u6765,\u5728\u4e0b\u4e00\u6b21\u89e6\u53d1\u65f6\u6bd4\u5bf9\n     *\/<\/em>\n    @CallSuper\n    override fun <strong>onAppWidgetOptionsChanged<\/strong>(\n        c<a href=\"https:\/\/app.applebyme.cn\/shengcheng-124.html\">\u79c1\u4ebaapp\u4e00\u952e\u751f\u6210\u5668<\/a>ontext: Context,\n        appWidgetManager: AppWidgetManager,\n        appWidgetId: Int,\n        newOptions: Bundle\n    ) {\n        <em>\/\/\u9700\u8981\u5728options change\u901a\u77e5\u91cc\u5224\u65ad\uff0cmin\u548cmax\u662f\u5426\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u5982\u679c\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u9700\u8981\u66f4\u65b0\u5e03\u5c40<\/em>\n    }\n}<\/code><\/pre>\n<h4>1.2.2.\u80a1\u7968\u5361\u7247\u7684\u81ea\u9002\u5e94\u65b9\u6848\u5b9e\u8df5<\/h4>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121127542.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121127542.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><\/figure>\n<p>RemoteViews\u65e0\u6cd5\u52a8\u6001\u8bbe\u7f6e\u5bbd\u9ad8\uff0c\u4f46\u662f\u53ef\u4ee5\u5728\u5e03\u5c40\u4e2d\u8bbe\u7f6e\u5bbd\u9ad8\uff0c\u4e3a\u4e86\u5b9e\u73b0\u5361\u7247\u7684\u81ea\u9002\u5e94\uff0c\u6211\u4eec\u4e0d\u5efa\u8bae\u5728\u5e03\u5c40\u4e2d\u7ed9layout_width\u548clayout_height\u8bbe\u7f6e\u56fa\u5b9a\u503c\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6700\u5927\u548c\u6700\u5c0f\u5bbd\u9ad8\u6765\u8fbe\u5230\u81ea\u9002\u5e94\u7684\u6548\u679c\uff1b<\/p>\n<p>\u4f8b\u5982\u80a1\u7968\u901a\u8fc7\u8c03\u6574ListView\u4e2d\u6bcf\u4e2aitem\u7684maxHeight\u548cmaxHeight\uff0c\u6765\u5b9e\u73b0\u81ea\u9002\u5e94\uff08\u4ee5\u4e0b\u63091080*2340\u5206\u8fa8\u7387\u4e3a\u4f8b\uff09\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:id=\"@+id\/stock_item\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:maxHeight=\"43.64dp\"\n    android:minHeight=\"40.97dp\"\n    android:background=\"@drawable\/pa_bg_stock_widget_item\"\n    android:paddingHorizontal=\"@dimen\/dp_7\"&gt;\n\n    &lt;include layout=\"@layout\/pa_widget_stock_item\" \/&gt;\n&lt;\/RelativeLayout&gt;<\/code><\/pre>\n<ul>\n<li>android:minHeight\u8ba1\u7b97\uff1a\uff08418-40*2\uff09\/ 3 \/ 2.75=40.97<\/li>\n<li>android:maxHeight\u8ba1\u7b97\uff1a\uff08440-40*2\uff09\/ 3\/ 2.75 = 43.64<\/li>\n<\/ul>\n<p>\u8ba1\u7b97\u8fc7\u7a0b\uff1a<\/p>\n<p>\u5728MIUI\u5c0f\u90e8\u4ef6\u8bbe\u8ba1\u89c4\u8303\u4e2d\uff0c\u5217\u51fa\u4e86Widget Host\u5728\u4e0d\u540c\u6a21\u5f0f\u4e0b\u7684\u5c3a\u5bf8\uff1a<\/p>\n<p>\u5982\u8868\u683c\u6240\u793a\uff0c4*2\u89c4\u683c\u7684\u5361\u7247\uff0c\u5176\u6700\u5c0f\u663e\u793a\u9ad8\u5ea6\u662f418px\uff0c\u6700\u5927\u663e\u793a\u9ad8\u5ea6\u662f440px\uff0c\u6211\u4eec\u8981\u6c42\u5185\u5bb9\u533a\u8ddd\u79bb\u5361\u7247\u5916\u8fb9\u8ddd\u6700\u5c0f\u662f40px\uff0c\u56e0\u6b64\uff0c\u5bf9\u4e8e4*2widget\u7684\u5185\u5bb9\u533a\u7684\u6700\u5c0f\u663e\u793a\u9ad8\u5ea6\u4e3a418-40*2\uff1b<\/p>\n<p>\u80a1\u79684*2\u6700\u591a\u663e\u793a3\u6761\u6570\u636e\uff0c\u56e0\u6b64\u6bcf\u6761\u6570\u636e\u7684\u6700\u5c0f\u663e\u793a\u9ad8\u5ea6\u4e3a\uff08418-40*2\uff09\/ 3\uff0c\u6362\u7b97\u6210dp\u4e3a40.97dp\uff1b\u6700\u5927\u663e\u793a\u9ad8\u5ea6\u7c7b\u4f3c\uff1b<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121133663.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121133663.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><\/figure>\n<h4>1.2.3.\u5176\u4ed6\u65b9\u6848\u5efa\u8bae<\/h4>\n<p>\u4f7f\u7528LinearLayout\u7b49\u5206\u5e03\u5c40\uff1a<\/p>\n<h4><img decoding=\"async\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121137305.png\"><img decoding=\"async\" class=\"j-lazy\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121137305.png\"><\/h4>\n<p>\u75ab\u60c5\u5361\u7247\u7684\u4e00\u79cd\u81ea\u9002\u5e94\u5e03\u5c40\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;FrameLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:padding=\"40px\"&gt;\n\n    &lt;TextView\n        android:id=\"@+id\/title\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\" \/&gt;\n\n    &lt;LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:orientation=\"horizontal\"\n        android:layout_gravity=\"bottom\"&gt;\n\n        &lt;LinearLayout\n            android:id=\"@+id\/item1\"\n            android:layout_width=\"0dp\"\n            android:layout_height=\"100dp\"\n            android:layout_marginEnd=\"10dp\"\n            android:layout_weight=\"1\"&gt;\n\n        &lt;\/LinearLayout&gt;\n\n        &lt;LinearLayout\n            android:id=\"@+id\/item2\"\n            android:layout_width=\"0dp\"\n            android:layout_height=\"100dp\"\n            android:layout_marginEnd=\"10dp\"\n            android:layout_weight=\"1\"&gt;\n\n        &lt;\/LinearLayout&gt;\n\n        &lt;LinearLayout\n            android:id=\"@+id\/item3\"\n            android:layout_width=\"0dp\"\n            android:layout_height=\"100dp\"\n            android:layout_marginEnd=\"10dp\"\n            android:layout_weight=\"1\"&gt;\n\n        &lt;\/LinearLayout&gt;\n\n        &lt;LinearLayout\n            android:id=\"@+id\/item4\"\n            android:layout_width=\"0dp\"\n            android:layout_height=\"100dp\"\n            android:layout_weight=\"1\"&gt;\n\n        &lt;\/LinearLayout&gt;\n    &lt;\/LinearLayout&gt;\n\n&lt;\/FrameLayout&gt;<\/code><\/pre>\n<p>\u5229\u7528LinearLayout\u7684android:layout_height\u5c5e\u6027\uff0c\u52a8\u6001\u5206\u914d\u6bcf\u4e2aitem\u7684\u5c3a\u5bf8\uff1b<\/p>\n<p>\u6ce8\uff1a\u80a1\u7968\u5361\u7247\u4e5f\u53ef\u4ee5\u91c7\u7528\u8be5\u65b9\u6848\u8fdb\u884c\u9002\u914d\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u6240\u6709\u4f7f\u7528ListView\u6216\u8005GridView\u7684\u5361\u7247\u5e03\u5c40\uff0c\u90fd\u53ef\u4ee5\u7528\u8be5\u65b9\u6848\u4ee3\u66ff\uff0c\u6765\u8fbe\u5230\u81ea\u9002\u5e94\u6548\u679c\uff0c\u4f46\u662f\u76f8\u5e94\u5730\u9700\u8981\u8fdb\u884c\u66f4\u591a\u81ea\u5b9a\u4e49\u7684\u5c01\u88c5\uff0c\u5f00\u53d1\u6210\u672c\u66f4\u9ad8\uff0c\u4f46\u662f\u6548\u679c\u6bd4\u8f83\u7406\u60f3\uff1b<\/p>\n<p>\u4f7f\u7528RelativeLayout\u76f8\u5bf9\u5e03\u5c40\uff1a<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121139733.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124121139733.png\" alt=\"MIUI Widget\u9002\u914d\u5efa\u8bae\u53ca\u793a\u4f8b\" \/><\/figure>\n<p>\u624b\u673a\u7ba1\u7406\u5361\u7247\u7684\u4e00\u79cd\u81ea\u9002\u5e94\u5e03\u5c40\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"horizontal\"\n    android:padding=\"40px\"&gt;\n\n    &lt;RelativeLayout\n        android:layout_width=\"0dp\"\n        android:layout_height=\"match_parent\"\n        android:layout_weight=\"1\"&gt;\n\n        &lt;ImageView\n            android:id=\"@+id\/icon\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\" \/&gt;\n\n        &lt;TextView\n            android:id=\"@+id\/score_description\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_alignParentStart=\"true\"\n            android:layout_alignParentBottom=\"true\"\n            android:text=\"\u624b\u673a\u5f88\u5b89\u5168\uff0c\u7ee7\u7eed\u4fdd\u6301\"\/&gt;\n\n        &lt;TextView\n            android:id=\"@+id\/score\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_<a href=\"https:\/\/app.applebyme.cn\/shengcheng-42.html\">app\u4e00\u952e\u751f\u6210<\/a>content\"\n            android:text=\"100\"\/&gt;\n    &lt;\/RelativeLayout&gt;\n\n\n    &lt;LinearLayout\n        android:layout_width=\"0dp\"\n        android:layout_height=\"match_parent\"\n        android:layout_weight=\"1\"\n        android:orientation=\"vertical\"&gt;\n\n        &lt;TextView\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"0dp\"\n            android:layout_weight=\"1\"\n            android:text=\"\u624b\u673a\u5783\u573e\"\/&gt;\n\n        &lt;TextView\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"0dp\"\n            android:layout_weight=\"1\"\n            android:text=\"\u5185\u5b58\u5360\u7528\"\/&gt;\n    &lt;\/LinearLayout&gt;\n\n&lt;\/LinearLayout&gt;<\/code><\/pre>\n<h3 id=\"_0_2\">1.3.\u603b\u7ed3<\/h3>\n<ul>\n<li>\u4ee5\u4e0a\u5404\u4e2a\u65b9\u6848\u53ea\u662f\u76ee\u524d\u4e3a\u6b62\uff0c\u53ef\u80fd\u7684\u90e8\u5206\u81ea\u9002\u5e94\u5b9e\u8df5\u5efa\u8bae\uff0c\u4e1a\u52a1\u9700\u8981\u6839\u636e\u81ea\u8eab\u60c5\u51b5\u6765\u5224\u65ad\u5982\u4f55\u9002\u914d<\/li>\n<li>\u4ee5\u4e0a\u5404\u4e2a\u65b9\u6848\uff0c\u90e8\u5206\u65b9\u6848\u53ef\u4ee5\u901a\u8fc7\u7ec4\u5408\u7684\u65b9\u5f0f\uff0c\u6765\u5b9e\u73b0\u66f4\u591a\u6548\u679c<\/li>\n<li>\u4ee5\u4e0a\u793a\u4f8b\u4ee3\u7801\u4e2d\u7684\u6570\u503c\u548c\u5e03\u5c40\uff0c\u53ea\u5177\u6709\u6f14\u793a\u6548\u679c\uff0c\u4e1a\u52a1\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8c03\u6574\uff0c\u8bf7\u52ff\u539f\u6837\u590d\u5236<\/li>\n<\/ul>\n<h2 id=\"_1\">2.\u5c0f\u90e8\u4ef6\u52a0\u8f7d\u6001\u5efa\u8bae\u53ca\u793a\u4f8b<\/h2>\n<h3 id=\"_1_0\">2.1.\u6982\u8ff0<\/h3>\n<p>\u80cc\u666f\u89c1\uff1a\u300aMIUI\u5c0f\u90e8\u4ef6\u89c4\u8303\u300b\u4e2d\u300c\u65e0\u5185\u5bb9\u573a\u666f\u300d\u3002\u6ca1\u6709\u914d\u7f6e\u52a0\u8f7d\u6001\u624b\u673a\u91cd\u542f\u6216\u8005\u684c\u9762\/\u8d1f\u4e00\u5c4f\u91cd\u542f\u4f1a\u5448\u73b0\u7a7a\u767d\u5361\u7247\uff0c\u5f71\u54cd\u6574\u4f53\u4f53\u9a8c\uff0c\u672c\u6a21\u5757\u4ecb\u7ecd\u4e86\u63a8\u8350\u7684\u52a0\u8f7d\u6001\u5b9e\u73b0\u65b9\u6848\u3002<\/p>\n<h3 id=\"_1_1\">2.2.\u65b9\u6848<\/h3>\n<p>\u9ed8\u8ba4\u5c55\u793a\u52a0\u8f7d\u6001(initialLayout\u6307\u5b9a\u52a0\u8f7d\u6001\u5e03\u5c40\u8d44\u6e90)\uff0c\u5f53\u6536\u5230update\u5e7f\u64ad\u65f6\u66f4\u65b0\u4e3a\u5b9e\u9645\u7684\u5e03\u5c40<\/p>\n<pre class=\"wp-block-code\"><code># \u5de5\u7a0b\u7ed3\u6784\n.\n\u2514\u2500\u2500 src\n    \u251c\u2500\u2500 main\n    \u2502   \u2514\u2500\u2500 java\n    \u2514\u2500\u2500 res\n        \u251c\u2500\u2500 drawable\n        \u2502   \u2514\u2500\u2500 loading.webp\n        \u251c\u2500\u2500 drawable-night\n        \u2502   \u2514\u2500\u2500 loading.webp\n        \u251c\u2500\u2500 layout\n        \u2502   \u251c\u2500\u2500 layout_example.xml\n        \u2502   \u2514\u2500\u2500 layout_loading.xml\n        \u2514\u2500\u2500 xml\n            \u2514\u2500\u2500 app_widget_simple.xml<\/code><\/pre>\n<h1><\/h1>\n<h5><\/h5>\n<h4><\/h4>\n<h4>layout_example.xml \u6b63\u5e38\u7684\u5e03\u5c40\u8d44\u6e90<\/h4>\n<h5><code>...<\/code><\/h5>\n<h4>layout_loading.xml \u52a0\u8f7d\u6001\u5e03\u5c40\u8d44\u6e90<\/h4>\n<pre class=\"wp-block-code\"><code>&lt;ImageView xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:scaleType=\"fitXY\"\n    android:src=\"@drawable\/loading.webp\" \/&gt;<\/code><\/pre>\n<h4><span class=\"wpcom_keyword_link\">app<\/span>_widget_simple.xml \u5c0f\u90e8\u4ef6\u914d\u7f6e\u8d44\u6e90<\/h4>\n<pre class=\"wp-block-code\"><code>&lt;appwidget-provider xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:minWidth=\"xxx\"\n    android:minHeight=\"xxx\"\n    ...\n    android:initialLayout=\"@layout\/layout_loading.xml\"\/&gt;<\/code><\/pre>\n<h4>AppWidgetProvider \u4f7f\u7528\u6b63\u5e38\u5e03\u5c40\u6587\u4ef6\u521b\u5efaRemoteViews<\/h4>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>ExampleWidget<\/strong> <strong>extends<\/strong> <strong>AppWidgetProvider<\/strong> {\n\n    @Override\n    <strong>public<\/strong> <strong>void<\/strong> <strong>onUpdate<\/strong>(Context context, AppWidgetManager appWidgetManager, <strong>int<\/strong>&#091;] appWidgetIds) {\n        <strong>super<\/strong>.onUpdate(context, appWidgetManager, appWidgetIds);\n        <strong>for<\/strong> (<strong>int<\/strong> appWidgetId : appWidgetIds) {          \n            <em>\/\/ \u6b63\u5e38\u5e03\u5c40\u6587\u4ef6\u521b\u5efaRemoteViews <\/em>\n            RemoteViews remoteViews = <strong>new<\/strong> RemoteViews(context.getPackageName(), \n            R.layout.example);\n            ...        \n        }\n    }\n}<\/code><\/pre>\n<p>\u5907\u6ce8\uff1a\u4ee5\u4e0a\u65b9\u6848\u4ec5\u505a\u53c2\u8003\u3002<\/p>\n<p>\u7f16\u8f91\uff1ayimen\uff0c\u5982\u82e5\u8f6c\u8f7d\uff0c\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttps:\/\/www.yimenapp.com\/kb-yimen\/12419\/<\/p>\n<p>\u90e8\u5206\u5185\u5bb9\u6765\u81ea\u7f51\u7edc\u6295\u7a3f\uff0c\u5982\u6709\u4fb5\u6743\u8054\u7cfb\u7acb\u5220<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.MIUI Widget\u5e03\u5c40\u81ea\u9002\u5e94\u65b9\u6848\u5efa\u8bae\u53ca\u793a\u4f8b1.1.\u6982\u8ff0\u80cc\u666f\u89c1\uff1a\u300aMIUI\u5c0f\u90e8\u4ef6\u6280\u672f\u89c4\u8303\u4e0e\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e\u300b\u4e2d\u300c\u5c0f\u90e8\u4ef6\u6280\u672f\u89c4\u8303\u548c\u8981\u6c42\u300d\u7b2c\u516b\u9879\u3002\u672c\u6a21\u5757\u4ecb\u7ecd\u4e86\u5e38\u7528\u7684\u51e0\u7c7bWidget\u5e03\u5c40\u5b9e\u73b0\u81ea\u9002\u5e94\u7684\u65b9\u6848\u30021.2.\u65b9\u6848\u4e0e\u793a\u4f8b1.2.1.\u5feb\u6377\u5361\u7247\u7684\u81ea\u9002\u5e94\u65b9\u6848\u5b9e\u8df5\u5feb\u6377\u529f\u80fd\u5361\u7247\u4e2d\u6bcf\u4e2aicon\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u662f<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[1345,1321,1097],"class_list":["post-1975","post","type-post","status-publish","format-standard","hentry","category-appshangjia","tag-widget","tag-1321","tag-1097"],"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/1975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=1975"}],"version-history":[{"count":0,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/1975\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=1975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=1975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=1975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}