CardView styling not showing on device - runtime

I am trying to make a custom style for a cardview on my activity. It works just as I want to in Android Studio. But when I run it on my device - Galaxy S7 Edge android 7.0 - the cardview attributes are not changing. It uses the background from the style of the layout, and the rest of the attributes - elevation, corner radius and card background seem to be ingnored.
I dont get any errors in the log.
The layout uses style="#style/AddItemStyle"
The card uses style="#style/AddItemStyle.CardView"
Thats the card style
<style name="AddItemStyle.CardView" parent="CardView">
<item name="cardBackgroundColor">#color/card_bg</item>
<item name="cardCornerRadius">15dp</item>
<item name="cardElevation">15dp</item>
</style>
Thats the layout style
<style name="AddItemStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#color/mySecondary</item>
<item name="colorAccent">#color/ColorMain</item>
<item name="editTextColor">#color/ColorMain</item>
<item name="android:background">#color/mySecondary</item>
</style>
In android studio
On my phone

For some reason removing android:theme="#style/AddItemStyle" from the activity in manifest fixed the problem. I don't know why but it worked.

Related

Splashscreen updates for Android 12

I recently updated my test phone for my app to Android 12. When I go to run my uno-platform app, the splashscreen no longer has my custom image on it. It now has the launcher icon. In doing some reading- this is a change that was done in Android 12. My question is how do I get my splashscreen to once again show my custom image? Will this change also work on Android 11 devices- or is something additional I need to do to handle both cases? Here is my code for my splashscreen- there is one for dark and one for light.
Light Mode Splashscreen(splash_screen.xml in drawable folder):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!-- background color -->
<color android:color="#dedcdc"/>
</item>
<item>
<!-- splash image -->
<bitmap
android:src="#drawable/splashscreen"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
Dark Mode Splashscreen(splash_screen_night.xml in drawable folder):
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!-- background color -->
<color android:color="#888689"/>
</item>
<item>
<!-- splash image -->
<bitmap
android:src="#drawable/splashscreen"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
Styles.xml(Light Mode):
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- This removes the ActionBar -->
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Splash Screen -->
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
</resources>
(In values-night folder for dark mode)Styles.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
<!-- This removes the ActionBar -->
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Splash Screen -->
<item name="android:windowBackground">#drawable/splash_screen_night</item>
</style>
</resources>
Starting Android 12, there is a new Splash Screen API that is replacing the current approach to creating splash screens on Android. To use this new API, you will need to migrate to it using steps described in the Android documentation here.
To support both new and older versions of Android, there is a AndroidX Splash Screen API in AndroidX Core library, but that is not bound in Xamarin version of the library at the time of writing (see the issue here on GitHub). Therefore you need to make sure the code for Android 12 support runs only on A12 and newer for now (while older targets can keep using the approach that worked for you until now).

How to fix ui actionbar nativescript error

After new version of nativescript, My page is over lap menu. How to fix its
Fix by app\App_Resources\Android\src\main\res\values-v21\style.xml
coding this on <style name="AppThemeBase21" parent="AppThemeBase">
<item name="android:windowTranslucentStatus">false</item>

NavigationPage BarBackgroundColor does not work on Xamarin.Android

I have XF app which gives the user an option to change from Light to Dark theme with a button click. I am using the below code:
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Japanese.NavBackgroundRes">
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{DynamicResource GridBackgroundColor}"/>
<Setter Property="BarTextColor" Value="{DynamicResource LabelTextColor}" />
</Style>
</ResourceDictionary>
This works perfectly on iOS but not in Android. The BarTextColor property works for both iOS and Android but the BarBackgroundColor only works on iOS. Anyone knows why that is? I am debugging on a physical device if that helps.
There is a concept in Android called the Material design.
Since Xamarin has adopted the Native Java Android Behavior in Xamarin.Android what happens is that the Android application picks the theme in its styles.xml file and uses that style to set the bar background colour.
But of course, there is a workaround. Whatever changes that you need to do on the Android side you will have to update it in the style file for it for eg:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#FFFFFF</item>
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#003399</item>
<item name="colorPrimaryDark">#003399</item>
<item name="colorControlHighlight">#003399</item>
<item name="colorAccent">#012348</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
</resources>
A change in colour here will directly reflect there, for eg ColorPrimary is your toolbar background colour (BarBackgroundColor).
UPDATE
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ToolbarTheme" >
</android.support.v7.widget.Toolbar>
Then get the toolbar something like this:
var toolbar=yourActivityContext.Window.DecorView.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
toolbar.SetBackgroundColor(Android.Graphics.Color.Your_Color);
//In case of hex color
toolbar.SetBackgroundColor(Android.Graphics.Color.ParseColor("#ebebeb"));
Use BackgroundColor instead of BarBackgroundColor for android.
use both properties for android and iphone.
<NavigationPage BarBackgroundColor="#F05123" BackgroundColor="#F05123" BarTextColor="White" >

How to set background image on xamarin forms master detail page and android

I want to set a navigation bar background image, but so far, no methods worked.
I don't know if I have to override the navigation-page renderer or if I have to change the "styles.xml", or if I have to override the Android "Toolbar", I have tried everything and I can't seem to find the solution.
I am using Xamarin Forms and Master Detail Page navigation.
I already tried changing styles.xml, making a custom toolbar layout, but doesn't mean I have done it right.
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>

How to make activity transparent in Xamarin android

I have refered here. But I just see a black background.
Then I use a Android standard Theme "ThemeTranslucentNoTitleBar". It is still a black background. So how to make a activity completely transparent?
protected override void OnCreate(Bundle bundle)
{
SetTheme(Android.Resource.Style.ThemeTranslucentNoTitleBar);
base.OnCreate(bundle);
SetContentView(Resource.Layout.xxx);
}
After trying lots of times. I find the resolution. You also have to set Android application theme. For exmaple <application android:theme="#android:style/Theme.Translucent" /> If you are using a custom application theme. Do not forget to set android:windowIsTranslucent = true
<style name="CustomTheme"
parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<item name="android:windowIsTranslucent">true</item>
</style>

Resources