我的应用程序的所有页面都是导航页面。我想知道如何在所有页面和导航栏部分放置图标?
我想编写一次代码并将其应用于所有页面。
因为当我进入嵌套页面时,图标消失了!
提前感谢帮助我的人!
答案 0 :(得分:1)
您可以在 Android 应用项目的工具栏中添加一个图标。
新模板表单应用中工具栏的默认布局是:
<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" >
</android.support.v7.widget.Toolbar>
为此添加一个图标:
<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" >
<ImageView
android:src="@drawable/star_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
更新:
在工具栏中为图像视图设置 id。
<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" >
<ImageView
android:id="@+id/imageView1"
android:src="@drawable/star_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
在 MainActivity LoadApplication(new App());
之后添加代码。
var imageview = FindViewById<ImageView>(Resource.Id.imageView1);
imageview.Click += delegate
{
Console.WriteLine("start clicked!");
};
<块引用>
如何在 Toolbaritem.xml 中输入 HorizontalOptions="End"?我要去页面右侧!
在 ImageView 中添加以下代码。
android:layout_gravity="end"
截图:
答案 1 :(得分:1)
只需在您的页面中使用:
<ContentPage
NavigationPage.HasNavigationBar="True"
NavigationPage.HasBackButton="False">
<NavigationPage.TitleView>
<Image />
</NavigationPage.TitleView>
YOUR VIEW
</ContentPage>