summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-04-18 09:46:51 -0700
committerJason Smith <jason.smith@xamarin.com>2016-04-18 09:46:51 -0700
commit75f112400223ea628ee008d311b7d5d54d98eafe (patch)
treeaf859c326a488cb0801fd57fca7bbce0cf0b4ad0 /Xamarin.Forms.Platform.Android
parentfc05a57e9dfa5b70e21b08f9c8f839b7986b4698 (diff)
downloadxamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.gz
xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.bz2
xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.zip
BarBackgroundColor and BarTextColor on TabbedPage (#96)
* [Core] Add properties to TabbedPage * [Controls] Add properties to test page * [iOS] Added BarBackgroundColor & BarTextColor to TabbedPage * [A] Added BarBackgroundColor & BarTextColor to TabbedPage * [UWP] Added BarBackgroundColor & BarTextColor to TabbedPage * [WinRT] Format file * [WinRT] Added BarBackgroundColor & BarTextColor to TabbedPage * [Docs] Updated docs
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs54
1 files changed, 52 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs
index f978028b..28fbf49c 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs
@@ -2,6 +2,9 @@ using System;
using System.Collections.Specialized;
using System.ComponentModel;
using Android.Content;
+using Android.Content.Res;
+using Android.Graphics;
+using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
@@ -13,6 +16,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
{
public class TabbedPageRenderer : VisualElementRenderer<TabbedPage>, TabLayout.IOnTabSelectedListener, ViewPager.IOnPageChangeListener, IManageFragments
{
+ Drawable _backgroundDrawable;
bool _disposed;
FragmentManager _fragmentManager;
TabLayout _tabLayout;
@@ -149,7 +153,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
tabs = _tabLayout = new TabLayout(activity) { TabMode = TabLayout.ModeFixed, TabGravity = TabLayout.GravityFill };
FormsViewPager pager =
_viewPager =
- new FormsViewPager(activity)
+ new FormsViewPager(activity)
{
OverScrollMode = OverScrollMode.Never,
EnableGesture = UseAnimations,
@@ -173,6 +177,8 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
UpdateIgnoreContainerAreas();
tabbedPage.InternalChildren.CollectionChanged += OnChildrenCollectionChanged;
+ UpdateBarBackgroundColor();
+ UpdateBarTextColor();
}
}
@@ -180,8 +186,12 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
{
base.OnElementPropertyChanged(sender, e);
- if (e.PropertyName == "CurrentPage")
+ if (e.PropertyName == nameof(TabbedPage.CurrentPage))
ScrollToCurrentPage();
+ else if (e.PropertyName == NavigationPage.BarBackgroundColorProperty.PropertyName)
+ UpdateBarBackgroundColor();
+ else if (e.PropertyName == NavigationPage.BarTextColorProperty.PropertyName)
+ UpdateBarTextColor();
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
@@ -318,5 +328,45 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
tab.SetIcon(ResourceManager.IdFromTitle(icon, ResourceManager.DrawableClass));
}
}
+
+ void UpdateBarBackgroundColor()
+ {
+ if (_disposed || _tabLayout == null)
+ return;
+
+ Color tintColor = Element.BarBackgroundColor;
+
+ if (Forms.IsLollipopOrNewer)
+ {
+ if (tintColor.IsDefault)
+ _tabLayout.BackgroundTintMode = null;
+ else
+ {
+ _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src;
+ _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid());
+ }
+ }
+ else
+ {
+ if (tintColor.IsDefault && _backgroundDrawable != null)
+ _tabLayout.SetBackground(_backgroundDrawable);
+ else if (!tintColor.IsDefault)
+ {
+ if (_backgroundDrawable == null)
+ _backgroundDrawable = _tabLayout.Background;
+ _tabLayout.SetBackgroundColor(tintColor.ToAndroid());
+ }
+ }
+ }
+
+ private void UpdateBarTextColor()
+ {
+ if (_disposed || _tabLayout == null)
+ return;
+
+ var textColor = Element.BarTextColor.ToAndroid().ToArgb();
+
+ _tabLayout.SetTabTextColors(textColor, textColor);
+ }
}
} \ No newline at end of file