3
Q
認識上配置的部件
A
回答
1
用一些佈局包裝您的小部件並覆蓋onInterceptTouchEvent方法。
2
我已經實現了你正在努力實現的目標。解決方案的想法是使用捆綁參數is_clicked = true將OnClick待定意圖設置爲小部件。
這是你可以做什麼:
在您使用RemoteViews設置你的小部件的佈局相同的地方,做了下:
/*
* Create pending intent to configuration activity
*/
Intent intent = new Intent(context, ConfigurationMainActivity.class);
/*
* Add values with this intent: widget id, and is_clicked = true
*/
Bundle extra = new Bundle();
extra.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
extra.putBoolean(ConfigurationMainActivity.IS_ON_WIDGET_CLICK_KEY, true);
intent.putExtras(extra);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
/*
* Set this intent to one of the views in the widget
*/
remoteViews.setOnClickPendingIntent(R.id.widget_main, pendingIntent);
2. 當用戶點擊小部件時,將打開ConfigurationMainActivity
活動。 在本次活動做了下編碼:
public static final String IS_ON_WIDGET_CLICK_KEY = "IS_ON_WIDGET_CLICK_KEY";
@Override
protected void onCreate(Bundle savedInstanceState)
{
// some usual stuff
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_configuration);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
// get the widget id that was transferred from on click event
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
// ---> here is what you asking for --->
// check whereas the widget was clicked by the user or not
boolean isOnWidgetClick = extras.getBoolean(IS_ON_WIDGET_CLICK_KEY, false);
if (isOnWidgetClick)
{
// ----- Do here whatever you want ------
}
else
{
// the code of first time widget configuration
}
...
...
}
注::
- IS_ON_WIDGET_CLICK_KEY - 僅僅是在多個類使用的常量。你可以在遠程視圖設置中看到它,這裏
希望,我可以幫助你。
相關問題
- 1. 識別默認的Outlook配置文件
- 2. NHibernate的 - 無法識別的配置部分休眠配置
- 3. Web部署 - 將root部署配置爲默認配置
- 4. APK文件不認識外部庫
- 5. 如何在部署上配置非默認的serviceAccount
- 6. 配置文件的默認位置 - MacOS?
- 7. 小部件配置
- 8. 默認PHP配置文件
- 9. 部落認證後端配置
- 10. 識別有效的配置文件
- 11. ClickOnce配置部署 - 配置文件
- 12. ASP.NET - 團結 - 閱讀從外部配置文件配置部件
- 13. 面部識別匹配的臉部
- 14. Eclipse插件測試的默認配置
- 15. Spring 3.1中的默認配置文件
- 16. maven的默認構建配置文件
- 17. Facebook的默認配置文件框FBML
- 18. asp.net中的默認配置文件
- 19. 默認部署Grails3和Angular配置文件
- 20. dojo小部件構造函數(params)合併配置與默認
- 21. Android Studio中不認識的性質宣佈簽約配置文件
- 22. Xamarin Studio不識別配置配置文件
- 23. 無法識別iPhone配置文件
- 24. 配置文件Web.config不被識別
- 25. log4j2配置文件未被識別
- 26. System.Speech.Recognition選擇識別配置文件
- 27. 想要使用來自<system.net>配置部分的SMTP的默認配置
- 28. Flex外部配置文件
- 29. Android小部件配置
- 30. 預配置Magento小部件
什麼是遠程視圖? –
我用更簡單的方法解決了它,只是用我的小部件容器攔截點擊。 –