Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How do I change title bar behaviour?

Hello. I was looking to Xamarin receipes on how to do certain things for Android apps, but nowhere how to actually change title bar behaviour (such like title bar background, text, icon, what the icon does when tapped, etc.) I mean I want to change the default title bar with the app icon and the executable app filename (like in this image):

The title says "Vyhledávač spojů" (in English like "Connection Search") and the icon is three stripes for a menu.

I can't find anything about how to do this certain thing. When I tried to change it in Visual Studio in some way (direct edit of the title bar in design window doesn't work unfortunately), the change didn't appear in the design window (how can I know if it actually works if it doesn't appear in preview window). Receipes doesn't contain anything about this in Android section (however I was able to find the iOS way to do this, which is unfortunately unusable for me), Google didn't find anything than the iOS thing :( Nor even in FAQ, nor even in forums. I'm trying to begin with Android apps making, but this seems a way too beyond. Is that something like know-how or what?

The picture was created with Photoshop, no programming was envolved in creating that illustration. It may be preview picture as a development sheet for creating the app...

Answers

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai
    edited January 2017

    The problem with customizing the Toolbar too far is that users will not be used to it. There is a great standard put into place by the previous ActionBar work and now with Material Design.

    The way you would do this currently is to add one or more custom views to the Toolbar. However you may want to read the overall spec for the Toolbar here:

    https://developer.android.com/reference/android/widget/Toolbar.html

    Thus it would be as simple as simply putting your View(s) in the Toolbar since it's a ViewGroup

    i.e.

     <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar">
    
        <My Custom Views...>
    
    </android.support.v7.widget.Toolbar>
    
  • Polda18Polda18 CZMember
    edited January 2017

    So I actually set up one major view (which will be blank) and place Toolbar here? And then make more views and place them in the Toolbar? Or how does it work? It's not much clear from the given link.

    EDIT:
    I downloaded example project Aquiant and it says that Toolbar was not installed (invalid layout). Does it mean it's not in standard Xamarin installation and I need to install it manually?

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    It's a highly customizable ViewGroup. You can technically do quite a bit with it. Google has a little bit of documentation on this here:

    https://developer.android.com/training/appbar/setting-up.html

    However you should be able to put any of your custom View items inside the Toolbar to get the functionality you're after. Sorry I don't have much more to go off of, but there's plenty of tutorials and samples online.

  • Polda18Polda18 CZMember

    This is what example Aquitant's layout says down:
    Bridge [resources.resolve] Couldn't resolve resource @layout/toolbar
    mono.android.DesignerException: You must specifiy a valid layout reference. The layout ID @layout/toolbar is not valid.
    at mono.android.DesignerSession.checkRenderResultForError(DesignerSession.java:175)
    at mono.android.DesignerSession.load(DesignerSession.java:225)
    at mono.android.DesignerSession.processMessage(DesignerSession.java:784)
    at mono.android.MessageListener.executeMessage(MessageListener.java:88)
    at mono.android.MessageListener$Runner.run(MessageListener.java:45)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: android.view.InflateException: You must specifiy a valid layout reference. The layout ID @layout/toolbar is not valid.
    at android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:131)
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:879)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:831)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:229)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at mono.android.DesignerSession.load(DesignerSession.java:210)
    ... 4 more

    I did not edit anything in it, just downloaded and opened.
    What does that mean? Means I have incomplete Xamarin installation in Visual Studio or what?

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Try to move the actual definition of what's inside the <include> instead.

        <include
            layout="@layout/toolbar" />
    

    to

    <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_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />
    

    Into the layout that you're looking at.

  • Polda18Polda18 CZMember

    Didn't understand. What to move where? The only layout that's working (actually displays) is AquiantanceRow.axml (Aquiant.Native.Droid). Nothing seems to work. The menu object (the axml in menus) does not exist, the android.support.v7.widget.Toolbar object does not exist (both not declared). That means something must be missing in my Xamarin installation... Using Visual Studio Community 2015, Xamarin with C# support. VS seems to not support Java (native syntax for Android apps), nor the Android environment itself :( And Xamarin does not seem to work as promoted :(

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Move the actual contents of the <include> directive.

    i.e.

    <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_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />
    

    Into your layout you're trying to open.

    There is a guide on the designer that you can follow here:

    https://developer.xamarin.com/guides/android/user_interface/designer_overview/

    I would have to double check to ensure our designer supports the <include>. I do believe it works, but what I'm having you do is to ensure it's not limiting it.

    Please note that these are Android Support widgets. Meaning that you need to ensure you have the proper support libraries installed in your application.

    With regards to custom controls, you need to ensure you have JDK 1.8 64 bit installed.

    https://developer.xamarin.com/releases/vs/xamarin.vs_4/xamarin.vs_4.2/#androiddesignercustomcontrols

  • Polda18Polda18 CZMember

    How do I check which JDK version is installed? I just updated Xamarin today.

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Inside the Tools -> Options -> Xamarin -> Android section there is a path to the JDK.

  • Polda18Polda18 CZMember

    I decided to leave Xamarin. Uninstalled it. Not only for the reason of complicated settings, but also for my classmates recommendation. Thank you for your support, anyway.

Sign In or Register to comment.