App Widget開發中按鈕使用指導
作者:147845412
AppWidget開發的概念你是否熟悉,本文向大家簡單介紹一下AppWidget開發中使按鈕不能用以及AppWidget初學指導,希望本文介紹對你有所幫助。
本文和大家重點學習一下AppWidget開發的概念,在AppWidget開發中我們可以使用button,但是卻不能是buttondisable為什么呢?請看本文詳細介紹。
AppWidget開發初學指導
在AppWidget開發中我們可以使用button,但是卻不能是buttondisable為什么呢
RemoteViews不能控制一個button可用和不可用的狀態,但是可以控制它的顯示與隱藏
因為我們可以利用這個造假
Java代碼
- <ButtonAndroid:idButtonAndroid:id="@+id/startbutton"android:text="Start"android:visibility="visible"></Button>
- <Buttonandroid:idButtonandroid:id="@+id/startbutton_disabled"android:text="Start"android:clickable="false"
- androidandroid:textColor="#999999"android:visibility="gone"></Button>
- <Buttonandroid:idButtonandroid:id="@+id/stopbutton"android:text="Stop"android:visibility="gone"></Button>
- <Buttonandroid:idButtonandroid:id="@+id/stopbutton_disabled"android:text="Stop"android:clickable="false"
- androidandroid:textColor="#999999"android:visibility="visible"></Button>
然后呢
當點擊startbutton的時候
Java代碼
- RemoteViewsremoteView=newRemoteViews(context.getPackageName(),R.layout.widget);
- remoteView.setViewVisibility(R.id.startbutton,View.GONE);
- remoteView.setViewVisibility(R.id.startbutton_disabled,View.VISIBLE);
- remoteView.setViewVisibility(R.id.stopbutton,View.VISIBLE);
- remoteView.setViewVisibility(R.id.stopbutton_disabled,View.GONE);
- AppWidgetManager.getInstance(context).updateAppWidget(AppWidgetId,remoteView);
當點擊stopbutton的時候
Java代碼
- RemoteViewsremoteView=newRemoteViews(context.getPackageName(),R.layout.widget);
- remoteView.setViewVisibility(R.id.startbutton,View.VISIBLE);
- remoteView.setViewVisibility(R.id.startbutton_disabled,View.GONE);
- remoteView.setViewVisibility(R.id.stopbutton,View.GONE);
- remoteView.setViewVisibility(R.id.stopbutton_disabled,View.VISIBLE);
- AppWidgetManager.getInstance(context).updateAppWidget(AppWidgetId,remoteView);
其實通過一個android:clickable="false",還有buuton的隱藏轉換造成了視覺的欺騙
【編輯推薦】
- AndroidWidget開發系列解讀
- AndroidWidget開發詳解
- 全面認識WebWidget開發
- DashBoard的Widget開發指南
- 解析AndroidWidget開發中如何構建Activity類
責任編輯:佚名
來源:
dev.10086.cn