Created
December 1, 2017 16:32
-
-
Save rdelrosario/24c8bce6d2dfd7b579bf31b39c0b046e to your computer and use it in GitHub Desktop.
Android Toolbar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void OnViewAdded(Android.Views.View child) | |
{ | |
base.OnViewAdded(child); | |
if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) | |
{ | |
var lastPage = Element?.Navigation?.NavigationStack?.Last(); | |
_toolbar = (Android.Support.V7.Widget.Toolbar)child; | |
_originalToolbarBackground = _toolbar.Background; | |
var originalContent = (Forms.Context as Activity)?.Window?.DecorView?.FindViewById<FrameLayout>(Window.IdAndroidContent); | |
if (originalContent != null) | |
{ | |
_originalWindowContent =originalContent.Foreground; | |
} | |
_parentLayout = new Android.Widget.FrameLayout(_toolbar.Context) | |
{ | |
LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent) | |
}; | |
//Create custom title view layout | |
_titleViewLayout = new Android.Widget.LinearLayout(_parentLayout.Context) | |
{ | |
Orientation = Android.Widget.Orientation.Vertical, | |
LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) | |
}; | |
//Create custom title text view | |
_titleTextView = new TextView(_parentLayout.Context) | |
{ | |
LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) | |
}; | |
//Create custom subtitle text view | |
_subTitleTextView = new TextView(_parentLayout.Context) | |
{ | |
LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) | |
}; | |
//Add title/subtitle to title view layout | |
_titleViewLayout.AddView(_titleTextView); | |
_titleViewLayout.AddView(_subTitleTextView); | |
//Add title view layout to main layout | |
_parentLayout.AddView(_titleViewLayout); | |
//Add main layout to toolbar | |
_toolbar.AddView(_parentLayout); | |
_toolbar.ChildViewAdded += OnToolbarChildViewAdded; | |
lastPage.PropertyChanged += LastPage_PropertyChanged; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment