[英]Android JAVA Widget does not show up in the list of widgets
我一直在嘗試創建一個基本的應用程序小部件,但無法使其顯示在小部件列表中。
代碼如下:
Widget_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dip"
>
<TextView
android:id="@+id/update"
style="@android:style/TextAppearance.Medium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:resizeMode="horizontal|vertical"
android:gravity="center_horizontal|center_vertical"
android:layout_margin="4dip"
android:text="@string/click_to_configure" >
</TextView>
</LinearLayout>
Widget_info.xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="72dp"
android:minWidth="146dp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/widget_layout"
android:resizeMode="horizontal|vertical"
android:initialKeyguardLayout="@layout/widget_layout"
android:widgetCategory="keyguard|home_screen"
android:configure="com.promethylhosting.countdowntowidget.SettingsActivity"
/>
表現:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.promethylhosting.countdowntowidget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SettingsActivity"
android:icon="@drawable/ic_launcher"
android:label="Countdown to... Widget">
<intent-filter>
<action android:name=".ACTION_WIDGET_CONFIGURE"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- mulitple actions must have multiple action filters 1:1 ratio between action/filter -->
</activity>
<reciever
android:name="CountdownToWidgetProvider"
android:icon="@drawable/ic_launcher"
android:label="Countdown To Widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</reciever>
</application>
</manifest>
我一直在搜尋,沒有找到解決此問題的任何解決方案。 所以我在這里發布。
預先感謝您閱讀本文檔和建議。
編輯:還有其他建議嗎?
在您的主要活動中嘗試此操作,在4.0列表中始終存在顯示小部件的問題
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
sendBroadcast(new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME));
setContentView(R.layout.main);
}
在這里也參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.