为了在Xamarin应用程序的导航栏中实现一个徽标(对于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服务调用确定的xlogo_small.png值动态地更改boolean。我更希望能够访问toolbar.axml,从Xamarin Forms共享项目动态编辑徽标,因为所有的逻辑都在这里。但是,我也没有在Xamarin.Android项目中找到一种方法。对于Xamarin窗体/ Android案例有什么解决方案吗?
发布于 2018-08-14 14:18:15
如何应用工具栏?我不知道如何实现tbh,但我知道如何获得默认的tbh。
在你的安卓项目中创建一个NavigationPageRenderer。
在"OnAttachedToWindow“覆盖中调用此方法
private void GetToolbar()
{
Android.Support.V7.Widget.Toolbar toolbar = null;
for (int i = 0; i < ChildCount; i++)
{
var child = GetChildAt(i);
toolbar = child as Android.Support.V7.Widget.Toolbar;
if (toolbar != null)
{
//Here toolbar is found.
//You might loop through the toolbars children and find your ImageView
break;
}
}
}https://stackoverflow.com/questions/51842879
复制相似问题