summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Garrido <jimmygarrido@outlook.com>2017-06-22 11:49:39 -0700
committerRui Marinho <me@ruimarinho.net>2017-06-22 19:49:39 +0100
commit330b5156164e7951e01bc2493f9ca54a2587783e (patch)
tree21bb6f9087dacefa3d0f0c8ab4cf2ebdfacb669a
parent668fe2f19c0069e016e6f1e5e210f873d451adde (diff)
downloadxamarin-forms-330b5156164e7951e01bc2493f9ca54a2587783e.tar.gz
xamarin-forms-330b5156164e7951e01bc2493f9ca54a2587783e.tar.bz2
xamarin-forms-330b5156164e7951e01bc2493f9ca54a2587783e.zip
Fix possible crash on API 21+ at launch when using Holo theme and FormsApplicationActivity (#961)
* Fix possible crash on API 21+ at launch * Do not use an explicit cast * Do not use C# 7 pattern matching
-rw-r--r--Xamarin.Forms.Platform.Android/Platform.cs24
1 files changed, 14 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs
index 4f6b33e9..467885ec 100644
--- a/Xamarin.Forms.Platform.Android/Platform.cs
+++ b/Xamarin.Forms.Platform.Android/Platform.cs
@@ -847,24 +847,28 @@ namespace Xamarin.Forms.Platform.Android
Color navigationBarTextColor = CurrentNavigationPage == null ? Color.Default : CurrentNavigationPage.BarTextColor;
TextView actionBarTitleTextView = null;
- if(Forms.IsLollipopOrNewer)
+ if (Forms.IsLollipopOrNewer)
{
int actionbarId = _context.Resources.GetIdentifier("action_bar", "id", "android");
- if(actionbarId > 0)
+ if (actionbarId > 0)
{
- Toolbar toolbar = (Toolbar)((Activity)_context).FindViewById(actionbarId);
-
- for( int i = 0; i < toolbar.ChildCount; i++ )
+ var toolbar = ((Activity)_context).FindViewById(actionbarId) as ViewGroup;
+ if (toolbar != null)
{
- if( toolbar.GetChildAt(i) is TextView )
+ for (int i = 0; i < toolbar.ChildCount; i++)
{
- actionBarTitleTextView = (TextView)toolbar.GetChildAt(i);
- break;
+ var textView = toolbar.GetChildAt(i) as TextView;
+ if (textView != null)
+ {
+ actionBarTitleTextView = textView;
+ break;
+ }
}
}
}
- }
- else
+ }
+
+ if (actionBarTitleTextView == null)
{
int actionBarTitleId = _context.Resources.GetIdentifier("action_bar_title", "id", "android");
if (actionBarTitleId > 0)