【发布时间】:2018-08-14 22:18:15
【问题描述】:
要在 Xamarin Forms 应用的导航栏中实现徽标(适用于 Android 案例),我使用以下 Toolbar.axml 文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/xlogo_small"
android:layout_gravity="right"
android:layout_alignParentRight="true" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
但现在我想根据应用程序加载后由 Web 服务调用确定的 boolean 值动态更改 xlogo_small.png。我宁愿访问toolbar.axml 以从Xamarin Forms Shared Project 动态编辑徽标,因为所有逻辑都位于其中。但是,我也没有在 Xamarin.Android 项目中找到一种方法。 Xamarin Forms / Android 案例的任何解决方案?
【问题讨论】:
-
在android项目中调用一个方法的简单依赖服务怎么样?它只会获取应用程序的当前工具栏,然后更改图像视图的 src 属性。
-
这是第一个想到的,但如果不是来自 MainActivity.cs,FindViewById 方法似乎不可用。我希望在直接从 Xamarin Forms 或通过依赖服务找到工具栏方面获得一些帮助
标签: android xamarin.forms xamarin.android