Android Xamarin-ActivityIndicator无效
我尝试在Android应用程序中添加ActivityIndicator。何时可以在xml中添加代码,或直接在代码页中添加代码。 但在代码中,我可以使用xamarin表单创建新的指示器,但我不知道如何将指示器添加到线性布局中 如果我将指示器添加到axml文件中,它会告诉我ActivityIndicator无效 第页: xml:Android Xamarin-ActivityIndicator无效,android,xamarin,Android,Xamarin,我尝试在Android应用程序中添加ActivityIndicator。何时可以在xml中添加代码,或直接在代码页中添加代码。 但在代码中,我可以使用xamarin表单创建新的指示器,但我不知道如何将指示器添加到线性布局中 如果我将指示器添加到axml文件中,它会告诉我ActivityIndicator无效 第页: xml: 如果您使用Xamarin.Android创建应用程序,则不应使用ActivityIndicator(Xamarin.Forms控件),而应使用小部件 来自Xamarin文档
如果您使用Xamarin.Android创建应用程序,则不应使用ActivityIndicator(Xamarin.Forms控件),而应使用小部件 来自Xamarin文档: 以下代码示例显示如何从工作线程使用进度条更新用户界面以通知用户进度:
public class MyActivity extends Activity {
private static final int PROGRESS = 0x1;
private ProgressBar mProgress;
private int mProgressStatus = 0;
private Handler mHandler = new Handler();
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.progressbar_activity);
mProgress = (ProgressBar) findViewById(R.id.progress_bar);
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100) {
mProgressStatus = doWork();
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
}
要将进度条添加到布局文件,可以使用元素。默认情况下,进度条是一个旋转的轮子一个不确定的指示器我在让我的进度条显示时遇到了一些问题。我还使用了本机android ProgressDialog,它的实现非常简单 我使用MainActivity并将其传递给ProgressDialog构造函数。似乎对我有用。在android和iOS上工作时,BeginInvokeOnMainThread为我修复了它。我认为这是因为覆盖必须在主UI线程上实例化
Device.BeginInvokeOnMainThread(() =>
{
MainActivity activity = Forms.Context as MainActivity;
progress = new ProgressDialog(activity);
progress.Indeterminate = true;
progress.SetProgressStyle(ProgressDialogStyle.Spinner);
progress.SetMessage("Connecting to server.. Please wait..");
progress.SetCancelable(false);
progress.Show();
});
不确定这是否正是您需要的,但它可能会帮助您解决问题 您正在混合使用Android原生widgets和Xamarin.Forms视图,Xamarin.Forms.ActivityIndicator是原生Android.Widget.ProgressBarOk@SushiHangover,但我如何在Xamarin中添加循环加载?我只在xamarin文档中找到了这些代码。请参阅
public class MyActivity extends Activity {
private static final int PROGRESS = 0x1;
private ProgressBar mProgress;
private int mProgressStatus = 0;
private Handler mHandler = new Handler();
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.progressbar_activity);
mProgress = (ProgressBar) findViewById(R.id.progress_bar);
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100) {
mProgressStatus = doWork();
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
}
Device.BeginInvokeOnMainThread(() =>
{
MainActivity activity = Forms.Context as MainActivity;
progress = new ProgressDialog(activity);
progress.Indeterminate = true;
progress.SetProgressStyle(ProgressDialogStyle.Spinner);
progress.SetMessage("Connecting to server.. Please wait..");
progress.SetCancelable(false);
progress.Show();
});