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辅助挂... 透视神器!hhpoker辅助挂(透视)hhpoker到底可以作必弊码(原来一直总是有挂)-哔哩哔哩1...
透视神器!模拟器打开hhpok... 透视神器!模拟器打开hhpoker(透视)hhpoker免费透视脚本(切实有透视)-哔哩哔哩1、首先...
透视攻略!hh poker软件... 透视攻略!hh poker软件(透视)hhpoker德州机器人(原来一直总是有透视)-哔哩哔哩1、很...
透视软件!潮汕激k辅助(辅助)... 透视软件!潮汕激k辅助(辅助)新九五辅助微信脚本(其实存在有挂)-哔哩哔哩一、新九五辅助微信脚本可以...
透视脚本!aapoker脚本怎... 透视脚本!aapoker脚本怎么用(透视)aapoker怎么拿好牌(一贯一直都是有透视)-哔哩哔哩1...
透视攻略!hhpoker到底可... 透视攻略!hhpoker到底可以作必弊码(透视)德扑HHpoker有挂吗(一贯一直总是有辅助器)-哔...
透视app!德州透视插件(透视... 透视app!德州透视插件(透视)hhpoker辅助器(真是有透视)-哔哩哔哩1、在德州透视插件插件功...
透视攻略!拱趴大菠萝有挂吗(透... 透视攻略!拱趴大菠萝有挂吗(透视)pokemmo手机版透视脚本(总是是有辅助器)-哔哩哔哩1、不需要...
透视脚本!欢聚水鱼脚本(辅助)... 您好,jj斗地主捕鱼辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
透视软件!hhpoker作必弊... 透视软件!hhpoker作必弊实战视频(透视)hhpoker透视脚本下载(其实存在有脚本)-哔哩哔哩...