当前位置: 编程技术>移动开发
本页文章导读:
▪Handler的施用 Handler的使用
class LoginHander extends Handler {
private static final int MSG_DIALOG_LOADING = 1;
private static final int MSG_DIALOG_CANCEL = 2;
private static final int MSG_SHOW_TOAST = 3;
public void actionShowProgressDlg(int id){
.........
▪ titlebar 标题栏展示进度条 titlebar 标题栏显示进度条
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.your_layout);
}然后你可任意调用
setPr.........
▪ 桌面小部件旋转屏后失效有关问题 桌面小部件旋转屏后失效问题
ppWidgetProvider
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
if(intent.getAction().equals("test.CLICK"))
{
CallTestMethod(context.........
[1]Handler的施用
来源: 互联网 发布时间: 2014-02-18
Handler的使用
class LoginHander extends Handler { private static final int MSG_DIALOG_LOADING = 1; private static final int MSG_DIALOG_CANCEL = 2; private static final int MSG_SHOW_TOAST = 3; public void actionShowProgressDlg(int id){ android.os.Message msg = new android.os.Message(); msg.what = MSG_DIALOG_LOADING; msg.arg1 = id; sendMessage(msg); } public void actionHideProgressDlg(int id){ android.os.Message msg = new android.os.Message(); msg.what = MSG_DIALOG_CANCEL; msg.arg1 = id; sendMessage(msg); } public void actionShowToast(final String str) { android.os.Message msg = new android.os.Message(); msg.what = MSG_SHOW_TOAST; msg.obj = str; sendMessage(msg); } @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_DIALOG_LOADING: showDialog(msg.arg1); break; case MSG_DIALOG_CANCEL: dismissDialog(msg.arg1); break; case MSG_SHOW_TOAST: Toast.makeText(Login.this, (String)msg.obj, Toast.LENGTH_LONG).show(); break; default: super.handleMessage(msg); break; } } }
[2] titlebar 标题栏展示进度条
来源: 互联网 发布时间: 2014-02-18
titlebar 标题栏显示进度条
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.your_layout); }然后你可任意调用 setProgressBarIndeterminateVisibility(true); setProgressBarIndeterminateVisibility(false);
[3] 桌面小部件旋转屏后失效有关问题
来源: 互联网 发布时间: 2014-02-18
桌面小部件旋转屏后失效问题
ppWidgetProvider @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if(intent.getAction().equals("test.CLICK")) { CallTestMethod(context); } } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; RemoteViews views=new RemoteViews(context.getPackageName(), R.layout.widget); Intent clickintent=new Intent("test.CLICK"); PendingIntent pendingIntentClick=PendingIntent.getBroadcast(context, 0, clickintent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.change_mode, pendingIntentClick); SetInitialLayout(context); appWidgetManager.updateAppWidget(appWidgetId, views); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
上述代码在旋转屏后失效,解决办法是
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if(intent.getAction().equals("test.CLICK")) { getIntent().putExtra("Just received click", true); CallTestMethod(context); } }
或者呢 如下使用
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { context.startService(new Intent(context, MyUpdateService.class)); }
public static class MyUpdateService extends Service { @Override public void onCreate() { super.onCreate(); } @Override public void onDestroy() { super.onDestroy(); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); // Update the widget RemoteViews remoteView = buildRemoteView(this); // Push update to homescreen pushUpdate(remoteView); } public RemoteViews buildRemoteView(Context context) { int layoutID = R.layout.widget; if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){ layoutID = R.layout.widget_landscape; } //Here is where you set your onclick listeners again since the remote views need to be refreshed/recreated RemoteViews updateView = new RemoteViews(context.getPackageName(),layoutID); // Create an Intent to launch ExampleActivity Intent intent = new Intent(this, yourAndroidActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); updateView.setOnClickPendingIntent(R.id.yourClickableViewHere, pendingIntent); return updateView; } @Override public void onConfigurationChanged(Configuration newConfig) { RemoteViews remoteView = buildRemoteView(this); // Push update to home screen pushUpdate(remoteView); } private void pushUpdate(RemoteViews updateViews) { ComponentName myWidget = new ComponentName(this, YourAppWidgetbackground-color: transparent; margin: 0px; color: #000000; font-size: 14px; vertical-align: bas
最新技术文章: