Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

xaml - How to place an icon in the navigation bar section in navigation pages

all the pages my app is navigation page . I wanted to know how to put an icon on all pages and in the navigation bar section ?

I want to write the code once and apply it to all pages.

Because when I enter the nested pages, icon disappears!

Thanks in advance to those who help me!

question from:https://stackoverflow.com/questions/66050913/how-to-place-an-icon-in-the-navigation-bar-section-in-navigation-pages

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could add an icon to the toolbar in the Android app project.

enter image description here

The default layout for the toolbar in a new template Forms app is:

<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>

Add an icon to this:

<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>

Updated:

Set id for the imageview in 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:id="@+id/imageView1"
    android:src="@drawable/star_small"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>

Add the code in MainActivity after LoadApplication(new App());.

 var imageview = FindViewById<ImageView>(Resource.Id.imageView1);
        imageview.Click += delegate
        {
            Console.WriteLine("start clicked!");
        };

How can I enter HorizontalOptions="End" in the Toolbaritem.xml? I want to go to the right side of the page!

Add the code below in ImageView.

android:layout_gravity="end"

Screenshot:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...