I have a Xamarin Forms TabbedPage which contains a NavigationPage and I'm setting a ToolbarItem with two white icons. For some reason they appear black when my icons are white:
Here is my Xaml code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Pick.Views"
x:Class="Pick.Views.MainView"
xmlns:utility="clr-namespace:Pick.Utility"
utility:ViewModelLocator.AutoWireViewModel="False">
<NavigationPage Title="{Binding Strings[Menu_MyPools]}">
<x:Arguments>
<views:PoolsView BindingContext="{Binding PoolsViewModel}"/>
</x:Arguments>
<NavigationPage.ToolbarItems>
<ToolbarItem Command="{Binding CreatePoolCommand}" Order="Primary" IconImageSource="ic_add_white_36dp.png">
</ToolbarItem>
<ToolbarItem Command="{Binding JoinPoolCommand}" Order="Primary" IconImageSource="ic_login_white_36dp.png">
</ToolbarItem>
</NavigationPage.ToolbarItems>
</NavigationPage>
I have tried setting AppThemeBinding and changing Styles.xml but nothing seems to work:
<ToolbarItem Command="{Binding CreatePoolCommand}" Order="Primary">
<ToolbarItem.IconImageSource>
<OnPlatform x:TypeArguments="ImageSource">
<On Platform="Android" Value="{AppThemeBinding Light=ic_add_white_36dp,Dark=ic_add_white_36dp}"/>
<On Platform="iOS" Value="{AppThemeBinding Light=ic_add_white_36pt,Dark=ic_add_white_36dp}"/>
</OnPlatform>
</ToolbarItem.IconImageSource>
</ToolbarItem>
Any ideas?
Here my styles.xml:
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#188223</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">#style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
</resources>
Tabbar.axml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="#android:color/white"
app:tabGravity="fill"
app:tabMode="fixed" />
Toolbar.axml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
I just figured out my issue. Turns out that I had XML files corresponding to my images which had a vector definition inside. Not sure if those were automatically created by one of my material design icons VS extension. Once I remove, I see my icons in the right color.
Related
I'm extending the prism sample here to also include icons, and some additional navigation. My goal is to add something like the code below (where the icon information is) and am unsure how to add that to either my view, or the view model correctly.
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:WebOfTrust.Views"
x:Class="WebOfTrust.Views.Client.WebOfTrustMainPage"
Title="{Binding Title}">
<TabbedPage.Children>
<!-- HOW DO I SET AN ICON FOR THESE? Either in the View or Model? -->
<NavigationPage Title="Contacts" >
<x:Arguments>
<local:Client.MyPeople.MyPeopleList/>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Places" Icon="Image7DoesntWork.png">
<x:Arguments>
<local:Client.MyPlaces.MyPlacesList/>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Docs" Icon="Image7DoesntWork.png">
<x:Arguments>
<local:Client.MyWallet.WalletCards/>
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
What normally works
I normally have a navigation page in the view where I specify the icon below.
<NavigationPage Title="Trust Anchor List">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<local:Client.TrustAnchorList />
</x:Arguments>
</NavigationPage>
Question
What is the right way to set an icon in either the view or the model when using Prism?
just add the icon attribute in the children of the tabbed page.
It works fine for me
<local:ContactUs Icon="Icons/History_Tab.png" Title="{Translate:TranslateExtension Text=NewMessage}" />
my icons are under a folder in the resources but you can put them anywhere.
The toolbar color is by default white and I would like to change it to blue. I was able to change almost everything but not that.
Toolbar.axml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
styles.xml
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorPrimary">#1b2b32</item>
<item name="android:textColorSecondary">#1c4d9e</item>
I found an approach. it is mixed with all the answers I read out there.
I used this answer from
Change color of ToolBarItem in XAML #Guillermo Daniel Arias.
on styles.XML
<item name="android:actionMenuTextColor">#1c4d9e</item>
on App.xml (On xamarin forms share project)
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="White"/>
<Setter Property="BarTextColor" Value="#004895"/>
</Style>
There are two possible approaches:
You change the BarBackgroundColor and BarTextColor of your NavigationPage. In your case, it would be something like that:
MainPage = new NavigationPage(new YourPage())
{
BarBackgroundColor = Color.White,
BarTextColor = Color.Blue
};
The other approach is to set your Android styles. You're already doing that, but I think that's wrong. Instead of android:textColorPrimaryandroid:textColorSecondary`, try something like that:
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FFFFFF</item>
<item name="colorSecondary">#0000FF</item>
<item name="colorAccent">#0000FF</item>
</style>
I think that android: may be the problem, because I'm doing exactly like I said and it's working.
in App.xml add this :
<Application.Resources>
<ResourceDictionary>
<Color x:Key="mRed">#65508F</Color>
<Color x:Key="mWhite">#FFFFFF</Color>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{StaticResource mRed}" />
<Setter Property="BarTextColor" Value="{StaticResource mWhite}" />
</Style>
</ResourceDictionary>
</Application.Resources>
new to Xamarin form.
I have the Following Tabbed Page. I wanted to do the following:
1) The background Color of the Tab is white Or One with Color,one with white color.
2) change the color of the underline of the Tab.
3) How many Tab can I have?
4) The fontsize for the Text.
5) Since each Tab has a contentPage, How to reference contentPage from outside instead inside the Tab as my contentpage is very long and complex.
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="White"
x:Class="MainPage2">
<ContentPage Title ="Page1" Icon="itemIcon1" WidthRequest="200" BackgroundColor="White">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="T1">
</Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
<ContentPage Title ="Page2" Icon="itemIcon2" WidthRequest="200" BackgroundColor="White">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="T2">
</Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
<ContentPage Title ="Page3" Icon="itemIcon3" WidthRequest="200">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="T3">
</Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
</TabbedPage>
Thanks
Styling the Tabs
Styling the tabs background color, text size, and highlight will need to be handled in your platform-specific projects. So, for Android this can be achieved by overriding the base styles with a custom theme, which you can modify in Resources > values > styles.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="CustomHighlight">#android:color/transparent</color>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:tabWidgetStyle">#android:style/Widget.TabWidget</item>
...
<!-- The rest of your styles would go here -->
...
</style>
<style name="Widget.TabWidget">
<item name="android:textAppearance">#style/TextAppearance.Widget.TabWidget</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>
<style name="TextAppearance.Widget.TabWidget">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#android:color/tab_indicator_text</item>
</style>
</resources>
(Liberally borrowed from this question: Android - How to Change Color of Selected Tab)
Your in-line background colors should suffice in your .xaml markup:
<ContentPage Title ="Page2" Icon="itemIcon2" WidthRequest="200" BackgroundColor="White">
For iOS, changing the highlight color is fairly trivial. In your AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
UITabBar.Appearance.TintColor = UIColor.Red;
global::Xamarin.Forms.Forms.Init();
...
Things get hairy from there, so I'll refer you to the developer documentation, which has a great walkthrough for creating a custom renderer: Customize Tab Bar on iOS
Tab Count
From the documentation
The user can scroll the collection of tabs that are across the top of the screen if that collection is too large to fit on one screen.
So really, the number of tabs is only limited to what makes sense from a user experience standpoint. I try not to have more than 6, personally, but your use-case may justify a few more.
I have defined a custom button in Android.
This is my styles.xml:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">#style/CustomButtonStyle</item>
</style>
<style name="CustomButtonStyle" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/custom_button</item>
</style>
And this is my custom_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="#drawable/btn_custom_normal" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="#drawable/btn_custom_disabled" />
<item android:state_pressed="true" android:drawable="#drawable/btn_custom_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="#drawable/btn_custom_focused" />
<item android:state_enabled="true" android:drawable="#drawable/btn_custom_normal" />
<item android:state_focused="true" android:drawable="#drawable/btn_custom_disabled_focused" />
<item android:drawable="#drawable/btn_custom_disabled" />
</selector>
Applying the custom background works, but all buttons are now smaller, and the captions of the buttons are smaller, too. Why? How can I make them appear exactly like the default buttons, but only with another background?
I have found my mistake. I have to select a Holo button style as parent:
<style name="CustomButtonStyle" parent="#android:style/Widget.Holo.Button">
<item name="android:background">#drawable/custom_button</item>
</style>
<Button
android:id="#+id/button_send"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#drawable/buttons"
android:drawablePadding="10dp"
android:gravity="left"
android:padding="15dp"
android:text="Button"
android:textColor="#fff"
android:textSize="15sp" />
Above is my code for Button in My xml file.
My button.xml code is
<item android:drawable="#drawable/btn_bg_hover"
android:state_pressed="true" />
<item android:drawable="#drawable/btn_bg_default"
android:state_focused="true" />
<item android:drawable="#drawable/btn_bg_default"/>
kindly help me how to add border to that button.
Note: #drawable/btn_bg_hover is image
User stroke tag Android - border for button
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#00FF00" android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#000000" />
You have to make your custom background drawable file and use it, the stroke property is the one you have to use for making border.
Steps :
Go to res -> drawable -> by right click -> new -> android drawable resource
copy paste this code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#00FF00"
android:angle="270" />
<stroke android:width="5px" android:color="#000000" />
</shape>
Here you see the stroke you can change values to make it in your way.
and use it as any components background by
<android:Background ="#drawable/yourCustomBorder.xml"> for example.