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崩溃问题。根据你的具体代码和情况,可能需要尝试多种方法来找到适合你的解决方案。

相关内容

热门资讯

透视揭露!德州来玩辅助器(透视... 透视揭露!德州来玩辅助器(透视)hhpoker辅助挂是真的吗,教程绝活儿(有挂分析)-哔哩哔哩在进入...
透视有挂!wepoker私人局... 透视有挂!wepoker私人局辅助器怎么用(透视)hhpkoer辅助器视频,教程指南书(有挂秘笈)-...
透视推荐!aapoker透视怎... 透视推荐!aapoker透视怎么用(透视)智星德州插件2024最新版,教程法子(真的有挂)-哔哩哔哩...
透视普及!hhpoker透视码... 透视普及!hhpoker透视码(透视)aapoker公共底牌,教程模板(有挂规律)-哔哩哔哩1、上手...
透视揭露!hhpoker有没有... 透视揭露!hhpoker有没有开挂(透视)pokemmo辅助器手机版下载,教程步骤(有挂秘诀)-哔哩...
透视了解!hhpkoer辅助挂... 透视了解!hhpkoer辅助挂是真的吗(透视)哈糖大菠萝攻略,教程学习(证实有挂)-哔哩哔哩1、金币...
透视解迷!约局吧怎么看有没有挂... 透视解迷!约局吧怎么看有没有挂(透视)wepoker有没有机器人,教程窍门(确实有挂)-哔哩哔哩亲,...
透视推荐!wepokerplu... 透视推荐!wepokerplus透视脚本免费(透视)菠萝德州透视脚本,教程教材(存在有挂)-哔哩哔哩...
透视辅助!wepoker辅助器... 透视辅助!wepoker辅助器安装包(透视)wepoker插件程序激活码,教程阶段(有挂分析)-哔哩...
透视总结!wepoker安装教... 透视总结!wepoker安装教程(透视)约局吧开挂神器是真的吗,教程方式(有挂猫腻)-哔哩哔哩所有人...