标签: xamarin.android

使用ValueAnimator使TextView闪烁不同的颜色

我想使用a ValueAnimator来使TextView两种不同颜色之间的文本颜色闪烁两次,但我想用XML创建动画.我找不到任何例子.任何帮助将不胜感激.

更新

下面的代码非常完美.颜色从黑色变为蓝色,蓝色变为黑色,黑色变为蓝色,蓝色变为黑色,每次反向重复之间的颜色变为500ms.然而,我试图从animator xml文件中使用它.

ValueAnimator colorAnim = ObjectAnimator.OfInt(objectToFlash, "textColor", (int)fromColor, (int)toColor);
colorAnim.SetDuration(500);
colorAnim.SetEvaluator(new ArgbEvaluator());
colorAnim.RepeatCount = 3;
colorAnim.RepeatMode = ValueAnimatorRepeatMode.Reverse;
Run Code Online (Sandbox Code Playgroud)

XML

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
        android:propertyName="textColor"        
        android:duration="500"
        android:valueFrom="@color/black"
        android:valueTo="@color/ei_blue"
        android:repeatCount="3"
        android:repeatMode="reverse" /> 
Run Code Online (Sandbox Code Playgroud)

ValueAnimator anim = (ObjectAnimator)AnimatorInflater.LoadAnimator(Activity, Resource.Animator.blinking_text);
anim.SetTarget(objectToFlash);
Run Code Online (Sandbox Code Playgroud)

使用xml会导致TextView文本颜色的颜色在500毫秒内变化多少次.

更新 我认为我需要的是在xml中模仿OfInt调用正在以编程方式执行的操作的关键帧.现在尝试这个,但到目前为止没有运气.

animation android xamarin.android

22
推荐指数
1
解决办法
3万
查看次数

跨平台登录Xamarin

我正在寻找一个日志实用程序,如NLog,Log4Net等...这将允许我登录我的Xamarin.Andriod,Xamarin.IOS和Xamarin.PCL项目.到目前为止我看过的所有记录器由于各种原因(大多数文件IO)都不支持PCL项目.是否有任何解决方案可用于支持跨平台方式的日志记录,包括PCL项目?如果没有,你是如何在PCL(设计模式等)中实现日志记录的?

谢谢

xamarin.ios xamarin.android ios xamarin

22
推荐指数
2
解决办法
9201
查看次数

在Xamarin.Forms中编写设备平台特定代码

我有以下Xamarin.Forms.ContentPage类结构

public class MyPage : ContentPage
{
    public MyPage()
    {
        //do work to initialize MyPage 
    }

    public void LogIn(object sender, EventArgs eventArgs)
    {
        bool isAuthenticated = false;
        string accessToken = string.Empty;

        //do work to use authentication API to validate users

        if(isAuthenticated)
        {
            //I would to write device specific code to write to the access token to the device
            //Example of saving the access token to iOS device
            NSUserDefaults.StandardUserDefaults.SetString(accessToken, "AccessToken");

            //Example of saving the access token to Android device …
Run Code Online (Sandbox Code Playgroud)

c# xamarin.ios xamarin.android xamarin xamarin.forms

22
推荐指数
3
解决办法
3万
查看次数

Xamarin:连接到本地托管的Web服务

我想创建一个web api应用程序来连接xamarin和android.
我已经尝试了很多,但一些连接错误即将到来.

我的代码如下:

public async Task<JsonValue> find(int ID)
    {
     using (HttpClient client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://localhost:49836");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage result = client.GetAsync("api/Product").Result;
           return JsonConvert.DeserializeObject<JsonValue>(await result.Content.ReadAsStringAsync());                
     }       
    }
    }
Run Code Online (Sandbox Code Playgroud)

我收到如下错误

System.Net.WebException:错误:ConnectFailure(连接被拒绝)---> System.Net.Sockets.SocketException:连接被拒绝

任何人都可以帮忙.任何帮助表示赞赏.

web-services xamarin.android xamarin

22
推荐指数
3
解决办法
2万
查看次数

什么是Java.Net.Uri和Android.Net.Uri之间的区别

我试图Urifile像这样的对象得到一个:

File file = new File("/sdcard/MyFolder/MyFile.txt");
var androidUri = Android.Net.Uri.FromFile(file).ToString();
var javaUri = file.ToURI().ToString();
Run Code Online (Sandbox Code Playgroud)

这将返回以下值:

androidUri = "file:///sdcard/MyFolder/MyFile.txt"
javaUri = "file:/sdcard/MyFolder/MyFile.txt"
Run Code Online (Sandbox Code Playgroud)

所以我的问题是Java.Net.Uri,Android.Net.Uri这两个值之间的区别是什么?什么时候应该使用它们?

更新

我找到了两个文档页面Java.Net.UriAndroid.Net.Uri,他们都说:

构建和解析符合RFC 2396的 URI引用.

因此,这肯定是一个错误,他们应该返回相同的字符串?

java android uri xamarin.android xamarin

22
推荐指数
2
解决办法
4393
查看次数

错误CS1703:已导入具有等效标识的多个程序集 - Xamarin + VSTS

我升级到最新的Xamarin for Visual Studio 2015(社区版),重新编译我的项目,检查了一些小的代码更改,我的VSTS构建服务器失败并显示以下错误消息:

[错误] CSC(0,0):错误CS1703:导入了具有等效标识的多个程序集:'C:\ Program Files(x86)\ Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll'和'C:\ WINDOWS\Microsoft.NET \框架\ v4.0.30319\mscorlib.dll中'.删除其中一个重复的引用.

互联网搜索通常几乎不会返回有关此问题的详细信息,并且在VSTS和Xamarin的上下文中根本没有重要信息.

我认为唯一与该问题相关的代码更改是由Visual Studio在项目文件中完成的:

在此输入图像描述

我只针对Android开发,使用的是Xamarin 4.2并使用JDK 8 u101.

不知道如何解决这个问题?

c# mono xamarin.android xamarin azure-pipelines

22
推荐指数
2
解决办法
3万
查看次数

Xamarin Android Build失败"outputAssembly的值无效"

几天前,我的解决方案似乎运行良好,但今天突然间Android项目无法构建.我没有得到错误,但我得到以下输出:

1>Build started.
1>Project "MyApp.Android.csproj" (Install target(s)):
1>Project "MyApp.csproj" (GetTargetFrameworks target(s)):
1>Done building project "MyApp.csproj".
1>Project "MyApp.csproj" (GetTargetFrameworks target(s)):
1>Done building project "MyApp.csproj".
1>Project "MyApp.csproj" (GetTargetPath target(s)):
1>Done building project "MyApp.csproj".
1>Project "MyApp.csproj" (GetTargetPath target(s)):
1>Done building project "MyApp.csproj".
1>Project "MyApp.csproj" (GetNativeManifest target(s)):
1>Done building project "MyApp.csproj".
1>Project "MyApp.csproj" (GetNativeManifest target(s)):
1>Done building project "MyApp.csproj".
1>"obj\Debug\MyApp.Android.dll;obj\Debug\MyApp.Android.dll" is an invalid value for the "OutputAssembly" parameter of the "Csc" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem".
1>Done …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin.android xamarin xamarin.forms

22
推荐指数
2
解决办法
7692
查看次数

手机进入睡眠状态后,保持wifi在前台服务中处于活动状

我想在手机锁定时从wifi接收数据包.问题是,当我锁定屏幕时,我的前台服务停止接收数据包.我正在使用Foreground Service,如下所示:

public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
    var notification = new Notification.Builder(this)
        .SetContentTitle(Resources.GetString(Resource.String.app_name))
        .SetContentText(Resources.GetString(Resource.String.notification_text))
        .SetSmallIcon(Resource.Drawable.ic_stat_name)
        .SetContentIntent(BuildIntentToShowMainActivity())
        .SetOngoing(true)
        .AddAction(BuildRestartTimerAction())
        .AddAction(BuildStopServiceAction())
        .Build();


    // Enlist this instance of the service as a foreground service
    StartForeground(Constants.SERVICE_RUNNING_NOTIFICATION_ID, notification);

    /*DO THIS EVEN WHEN SCREEN IS LOCKED*/

    var powerManager = (PowerManager)GetSystemService(PowerService);
    _wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "WakeLockTag");
    _wakeLock.Acquire();

    var wifiManager = (WifiManager)GetSystemService(WifiService);
    _wifiLock = wifiManager.CreateWifiLock(WifiMode.FullHighPerf, "xamarin_wifi_lock");
    _wifiLock.Acquire();

    if (!powerManager.IsIgnoringBatteryOptimizations("com.xamarin.xample.foregroundservicedemo") ||
        !_wakeLock.IsHeld || !_wifiLock.IsHeld)
        throw new InvalidOperationException("OPTIMIZATIONS NOT ACTIVE");

    string msg = timestamper.GetFormattedTimestamp();
    Log.Debug(TAG, msg); …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin.android xamarin xamarin.forms

22
推荐指数
1
解决办法
1046
查看次数

每次更新应用程序时是否需要创建新的SQLite数据库?

我有一个我想开发的Xamarin Forms应用程序.它将有一个SQLite数据库,我希望在iOS和Android上提供它.数据库将使用来自云上的SQL Server数据库的数据填充初始种子数据.我想这将是大约500行数据,每行大约1Kb.

我不明白的是何时以及如何填充这个.我是否应该尝试将数据放入CSV文件并在安装应用程序或首次启动时填充数据库?除了使用大量插入语句填充代码中的行之外,填充种子数据的常规方法是什么.

关于如何正常完成的任何帮助或建议(我认为大多数人都以同样的方式完成)将不胜感激.

谢谢

sqlite xamarin.ios xamarin.android xamarin

21
推荐指数
2
解决办法
2099
查看次数

Xamarin Cross平台中的全局异常处理

你能告诉我如何在Xamarin Cross平台项目中处理全局异常(没有App崩溃).

cross-platform xamarin.ios xamarin.android xamarin xamarin.forms

21
推荐指数
1
解决办法
1万
查看次数