I need to dynamically create a Toolbar inside in activity. Due to design reasons I cannot create it in the AXML and must create it fully programatically. Sadly most of the advanced design properties do not have coded equivalents.
How can I configure a toolbar purely in code, to match the following AXML? Please note I'm using a Support.V7.Widget.Toolbar so that my app is backward compatible with Android 5.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_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
Method 1 : Create then Configure
My current code:
var toolbar = new Toolbar(this);
toolbar.Title = "View Options";
// the following properties exist but are only GETTERS! .. how do I change them?
toolbar.Width = "parent_width";
toolbar.Height = "wrap_content";
// the following properties don't exist.. what do I do?
toolbar.MinHeight = "?aatr/actionBarSize";
toolbar.Background = "?attr/colorPrimary";
toolbar.Theme = "@style/ThemeOverlay.AppCompat.Dark.ActionBar";
toolbar.PopupTheme = "@style/ThemeOverlay.AppCompat.Light";
Method 2 : Use Attributes
Alternatively I can pass "attributes" to the Toolbar at the time of construction, but there is no way to "create" an IAttributeSet or do change attributes within a set!
I need to create the PINK toolbar in the following image:
Edit: Sorry, my question is different from this which is only about creating views. I need to create a toolbar in a view with a lot of more properties.