Xamarin 如何在工具栏中添加徽标图像
嗨,Xamarin android新手。我有一个问题: 1) 如何在工具栏中添加图像徽标 W X H的图像徽标尺寸是多少 这里是工具栏Xamarin 如何在工具栏中添加徽标图像,xamarin,xamarin.android,Xamarin,Xamarin.android,嗨,Xamarin android新手。我有一个问题: 1) 如何在工具栏中添加图像徽标 W X H的图像徽标尺寸是多少 这里是工具栏 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent" />
如何在工具栏中添加图像徽标
首先,需要正确创建自定义工具栏,可以按照创建自定义工具栏
然后,您可以简单地在工具栏布局中添加任何元素:
Toolbar.axml(house.png
位于Resources/drawable
文件夹中):
有关Android布局的详细信息,请参阅的“布局参数”部分。看到您的解决方案真的很高兴。安装V7 appCompat时遇到问题,请帮助我。在我的步骤中,我右键单击项目下的组件以获得V7 AppCompat。首先,所有包含Xamarin.Android.Support.compat和其他Xamarin.Android.Support…r的DLL都导入到组件和引用文件夹中。过了一会儿,为什么在引用文件夹中的所有DLL都会附加一个黄色三角形警告标志,以Xamarin.Android.Support开头?这意味着什么?当我右键单击Reference folder并选择Nuget Manager时,它显示安装了V7 AppCompat。发生了什么?某些依赖项可能未完全安装。请再次尝试卸载所有nuget软件包,并通过nuget安装xamarin.android.support.v7.appcompat
。首先通过组件获取支持v7 appcompat。单击参考文件夹时,它将显示v7 Appcompat:1)已安装的25.1.1--卸载btn
2。版本25.1.0——更新btn
我需要单击更新btn以获得25.1.0,否则我将获得黄色三角形警告标志。Is 25.1.1有问题吗?必须使用25.1.0版吗?谢谢,我无法重现你描述的问题。我可以毫无问题地安装和使用v7 Appcompat 25.1.1
。你能分享一个可以重现问题的基本项目演示吗?我正在使用Vs2015更新3。我上传了黄色三角形的图片。点击更新到25.1.0后,一切恢复正常。
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent" />
<ImageView
android:id="@+id/toolbarimage"
android:layout_marginTop="12dp"
android:layout_marginBottom="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/Logo" />
</android.support.v7.widget.Toolbar>
<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:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/house" />
</Toolbar>
[Activity(Label = "ToolbarDemo", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetActionBar(toolbar);
ActionBar.Title = "";
}
}
<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:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:adjustViewBounds="true"
android:src="@drawable/house" />
</Toolbar>