I am Searching for a proper fix on how to change the Color of the Pickers (Date & Time) in Xamarin Forms. I already have the Custom Renderer to customize the Dialog, but is there also a similar possibility to customize the Background Color of the displayed Picker itself(and the annoying Pink line) on all Instances at once?
I found out how to make it, but my solution is not that elegant since i have to define the Background Color on each Instance throughout the App.
-> i want the Blue Box behind the 16:00 to disappear
the code to the picture i have as follows:
<TimePicker Grid.Row="5"
Grid.Column="0"
x:Name="BtnTime2"
Format="t"/>
<Button Grid.Row="5"
Grid.Column="1"
x:Name="BtnTime2Now"
CornerRadius="15"/>
<DatePicker Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="2"
x:Name="BtnDate"
Format="D"
BackgroundColor="#00000000"/>
Hope anybody of you guys can help me
ok nevermind...
i already had the solution in my App.xaml
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Arbeitszeitrechner_Forms.App">
<Application.Resources>
<ResourceDictionary>
...some more Styles here...
<Style TargetType="TimePicker">
<Setter Property="BackgroundColor" Value="#00000000"/>
<Setter Property="TextColor" Value="{StaticResource Text}"/>
</Style>
<Style TargetType="DatePicker">
<Setter Property="BackgroundColor" Value="#00000000"/>
<Setter Property="TextColor" Value="{StaticResource Text}"/>
</Style>
</ResourceDictionary>
</Application.Resources>
I have created a Xamarin Android Shell app. All the labels and Entries are in blank color and don't display on the android device until I change it to black or other colors. Below is a code snippet for the login page.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="VaxineApp.Views.Login.LoginPage"
xmlns:local="clr-namespace:VaxineApp.Renderers"
Shell.FlyoutBehavior="Disabled"
Shell.NavBarIsVisible="False">
<ContentPage.Content>
<StackLayout Padding="40" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
<Label Text="Welcome to Login Page" />
<Entry Placeholder="Email or Phone"></Entry>
<Entry Placeholder="Password"></Entry>
<Button Text="Sign in"></Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
I don't know whether I am missing something. That hasn't happened to me before.
See how this code renders on my Android device.
Page markup
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage NavigationPage.HasNavigationBar="false" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ConnectedLifeView.NativeApp.Pages.LoginSuccessPage">
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="0" Padding="0">
<WebView x:Name="webView" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#02114D"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Output
I tried adding background color to content page and setting WebView background color to Transparent but it has no effect either.
My all other pages have proper background but this page looks a bit weird as it shows white background while the URL loads in WebView.
Xamarin.Forms version: 4.2.0.815419
Platform: Android
If you want to change webview background color, another way is to use custom render.
public class TransparentWebViewRenderer:WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
// Setting the background as transparent
this.Control.SetBackgroundColor(Android.Graphics.Color.AliceBlue);
}
}
Wondering if anyone else has run into the following issue.
I've got my App.MainPage wrapped in a navigation page
MainPage = new NavigationPage(new MyPage());
From MyPage I navigate to a user account page which is a TabbedPage
await Navigation.PushAsync(new MyAccountTabbedPage());
and here's the xaml (pretty simple)
<TabbedPage.Children>
<userAccount:SitesTab />
<userAccount:ProjectsTab />
<userAccount:SettingsTab />
</TabbedPage.Children>
Now here's where it gets fun. From within my SitesTab, I need to show a ListView that contains ContextActions
<AbsoluteLayout>
<ListView AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
ItemsSource="{Binding ListItems}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="Do Stuff"/>
<MenuItem Text="Delete Stuff" IsDestructive="True"/>
</ViewCell.ContextActions>
<StackLayout>
<Label Text="{Binding .}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</AbsoluteLayout>
The issue I'm running up against is that the context action on Android doesn't cover/replace the NavigationBar, but rather pushes it down and screws everything up.
Before Context
After Context
So what's up here? Has anyone figured out a way around this? That context menu at the top of the page should cover over the NavigationBar instead of push everything down.
turns out I needed the following in my app compat theme
<style name="myActivityTheme" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionModeOverlay">true</item>
</style>
I just got started with React Native for Android, and I'm trying to figure out if there's a way to change the status bar color for Android...
Like this?
You can use React Native Status Bar(detailed description here). All you need to do is wrapping navigator with a view and adding a StatusBar component above it. Don't forget to import StatusBar from 'react-native' package.
<View>
<StatusBar
backgroundColor="blue"
barStyle="light-content"
/>
<Navigator
initialRoute={{statusBarHidden: true}}
renderScene={(route, navigator) =>
<View>
<StatusBar hidden={route.statusBarHidden} />
...
</View>
}
/>
</View>
One thing I've noticed is that you should style the parent View with flex:1, without it you'll just see a white blank screen. It's not mentioned in RN Documents though.
Yes you can:
import {StatusBar} from 'react-native';
componentDidMount() {
StatusBar.setBarStyle( 'light-content',true)
StatusBar.setBackgroundColor("#0996AE")
}
You can use react-native in-build StatusBar function
import {StatusBar} from 'react-native';
render() {
return <View>
<StatusBar
backgroundColor="#264d9b"
barStyle="light-content"
/>
... //Your code
</View>
}
reference:
https://facebook.github.io/react-native/docs/statusbar
I've made an npm package to control the StatusBar in android
https://www.npmjs.com/package/react-native-android-statusbar
The color changes do not reflect for versions before 21
There is no way currently to do that from JS. You can customize it by using a custom theme. Check out android/src/main/res/values/styles.xml file from your project (template is here: https://github.com/facebook/react-native/blob/master/local-cli/generator-android/templates/src/app/src/main/res/values/styles.xml) and read more here: https://developer.android.com/training/material/theme.html
Add this code on your header component
androidStatusBarColor="#34495e"
add color.xml in ..android/app/src/main/res/values and pate following code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- color for the app bar and other primary UI elements -->
<color name="colorPrimary">#3F51B5</color>
<!-- a darker variant of the primary color, used for
the status bar (on Android 5.0+) and contextual app bars -->
<color name="colorPrimaryDark">#A52D53</color>
<!-- a secondary color for controls like checkboxes and text fields -->
<color name="colorAccent">#FF4081</color>
</resources>
copy and pate following code in ..android/app/src/main/res/values/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
If you are using Expo for React Native then here is the solution for setting Android Status Bar Color.
First of all, In your app.json file add the code:
{
"expo": {
"sdkVersion": "Your given Version",
"androidStatusBar": {
"backgroundColor": "#4e2ba1" (Your desirable android Status Bar Color before the app loads)
}
}
}
And then Go to Your Main Component or App.js, import 'StatusBar' from 'react-native'. Then add Following Code in return:
return(
<View style={{flex: 1}}> (Do not forget to style flex as 1)
<StatusBar translucent backgroundColor="rgba(0,0,0,0.2)"/>
<Your Code>
</View>
);
Here, we are setting the status bar color as Black but with 0.2 opacity. Your statusBar Color will be the same as your headerStyle background Color for Stack Navigator but a bit darker. For standard Android App, this is how the StatusBar color is set. Also, Make it translucent so that your app draws under the status Bar and looks nice.
It hope this works perfectly for you.
There is no exposed API for now. This will work only from Android 5.0.
Working on a bridge module to achieve the same. Will keep you posted
Just add the following code to your App.js file inside your class component.
componentDidMount(){
StatusBar.setBarStyle( 'light-content',true)
StatusBar.setBackgroundColor("Your color Hex-code here")
}
And add this to your import statements.
import {StatusBar} from 'react-native';
If you guys are using expo then just add this in the app.json
"androidStatusBar": {
"backgroundColor": "#ffffff",
"barStyle":"dark-content"
}
Refer: https://docs.expo.io/versions/latest/guides/configuring-statusbar/
Use backgroundColor Prop in the StatusBar Component
<StatusBar backgroundColor="#yourColor" />
Check docs more information : https://reactnative.dev/docs/statusbar
You can use react-native-navigation-bar-color this module to change NavigationBar, install it using npm i react-native-navigation-bar-color