Android Xamarin中,Android 6.x中的“ProgressBar.SetProgress crash”
创始人
2024-08-19 12:30:23
0

在Android Xamarin中,有时候在Android 6.x中使用ProgressBar的SetProgress方法可能会导致崩溃。以下是可能的解决方法:

  1. 确保在使用SetProgress方法之前,ProgressBar对象已经正确初始化。例如,在OnCreate方法中调用SetContentView之后,使用FindViewById方法获取ProgressBar对象,并确保它不为null。
ProgressBar progressBar = FindViewById(Resource.Id.progressBar1);
if (progressBar != null)
{
    progressBar.SetProgress(50, true);
}
  1. 尝试使用Handler在主线程上更新ProgressBar的进度。这可以通过将SetProgress方法包装在Handler的Post方法中来实现。
Handler handler = new Handler();
ProgressBar progressBar = FindViewById(Resource.Id.progressBar1);
if (progressBar != null)
{
    handler.Post(() =>
    {
        progressBar.SetProgress(50, true);
    });
}
  1. 确保在运行SetProgress方法之前,ProgressBar已经完成了布局和测量。可以尝试在OnWindowFocusChanged方法中使用PostDelayed方法来延迟运行SetProgress方法。
ProgressBar progressBar;
protected override void OnWindowFocusChanged(bool hasFocus)
{
    base.OnWindowFocusChanged(hasFocus);
    progressBar = FindViewById(Resource.Id.progressBar1);
    if (progressBar != null && hasFocus)
    {
        progressBar.PostDelayed(() =>
        {
            progressBar.SetProgress(50, true);
        }, 100);
    }
}

这些解决方法中的任何一种都可能帮助你解决Android 6.x中的ProgressBar.SetProgress崩溃问题。根据你的具体代码和情况,可能需要尝试多种方法来找到适合你的解决方案。

相关内容

热门资讯

玩家必知教程!wepoker公... 玩家必知教程!wepoker公共底牌(辅助挂)好像是有挂(真的有挂)1、超多福利:超高返利,海量正版...
重大通报!wepoker软件安... 重大通报!wepoker软件安装包(辅助挂)一直真的是有挂(有挂猫腻)1、在wepoker软件安装包...
攻略讲解!wepoker辅助器... 攻略讲解!wepoker辅助器免费(辅助挂)一直是真的有挂(有挂秘笈)1、超多福利:超高返利,海量正...
分享认知!pokemmo脚本手... 分享认知!pokemmo脚本手机版(辅助挂)确实是真的有挂(有挂辅助)1、pokemmo脚本手机版脚...
大神推荐!wepoker辅助器... 大神推荐!wepoker辅助器有哪些功能(辅助挂)本来真的是有挂(有挂方针)1)wepoker辅助器...
研究成果!wepoker智能辅... 研究成果!wepoker智能辅助插件(辅助挂)确实存在有挂(真实有挂)1、金币登录送、破产送、升级送...
科技通报!wpk是真的还是假的... 科技通报!wpk是真的还是假的(辅助挂)确实有挂(讲解有挂)该软件可以轻松地帮助玩家将wpk是真的还...
一分钟了解!we-poker是... 一分钟了解!we-poker是什么软件(辅助挂)竟然真的有挂(有挂教程)1、we-poker是什么软...
重大通报!wepoker辅助器... 重大通报!wepoker辅助器软件下载(辅助挂)好像有挂(有挂方针)1、上手简单,内置详细流程视频教...
科普常识!德州透视脚本(辅助挂... 科普常识!德州透视脚本(辅助挂)都是真的有挂(有挂存在)1、德州透视脚本辅助器安装包、德州透视脚本辅...